summaryrefslogtreecommitdiff
path: root/testshl2/inc/testshl/additionalfunc.hxx
blob: 463d1ae87280cfbd0c220cfca0eaeb45bac89fed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef ADDITIONALFUNC_HXX
#define ADDITIONALFUNC_HXX

#include "testshl/autoregister/registertestfunction.h"
#include "sal/types.h"

extern "C" void SAL_CALL RegisterAdditionalFunctions(FktRegFuncPtr _pFunc);

#define NOADDITIONAL \
void RegisterAdditionalFunctions(FktRegFuncPtr){}

namespace {

enum T2_OSType {
    T2_OS_WNT32 = 1,
    T2_OS_UNIX,
    T2_OS_OS2
};

inline T2_OSType getOSType()
{
#if defined WNT
    return T2_OS_WNT32;
#elif defined OS2
    return T2_OS_OS2;
#else
    return T2_OS_UNIX;
#endif
}

}

#define TESTSHL2_UNO_BOOTSTRAP(file)                                                    \
void RegisterAdditionalFunctions(FktRegFuncPtr _pFunc)                                  \
{                                                                                       \
   com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory> xMS;     \
   com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > xComponentContext; \
   try {                                                                                \
       if (strlen(#file) > 0) {                                                         \
           ::rtl::OUString iniFile(rtl::OUString::createFromAscii(#file));              \
           if (getOSType() == T2_OS_WNT32 || getOSType() == T2_OS_OS2) {                \
               iniFile += ::rtl::OUString::createFromAscii(".ini");                     \
           } else {                                                                     \
               iniFile += ::rtl::OUString::createFromAscii("rc");                       \
           }                                                                            \
           xComponentContext = cppu::defaultBootstrap_InitialComponentContext(iniFile); \
       } else {                                                                         \
           xComponentContext = cppu::defaultBootstrap_InitialComponentContext();        \
       }                                                                                \
       xMS.set(xComponentContext->getServiceManager(), com::sun::star::uno::UNO_QUERY); \
       comphelper::setProcessServiceFactory(xMS);                                       \
   }                                                                                    \
   catch (::com::sun::star::uno::Exception e ) {                                        \
       rtl::OString aError;                                                             \
       aError = rtl::OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US);           \
       printf("Error at UNO bootstrap time caught: %s\nMust quit.\n", aError.getStr()); \
       exit(1);                                                                         \
   }                                                                                    \
}

#endif