]> rtime.felk.cvut.cz Git - orte.git/blob - orte/contrib/pharlap/ortedll.c
Reformat the sources with orte/uncrustify script
[orte.git] / orte / contrib / pharlap / ortedll.c
1 #include "windows.h"\r
2 #include "ortedll.h"\r
3 #include <assert.h>\r
4 \r
5 #ifdef _DEBUG\r
6         #define ASSERT(x)               assert(x)\r
7 #else\r
8         #define ASSERT(x)\r
9 #endif\r
10 \r
11 \r
12 #define COUNTOF(arr)            (sizeof(arr)/sizeof((arr)[0]))\r
13 \r
14 #ifdef _DEBUG\r
15         #define __ORTE_DLL_NAME         "orted.dll"\r
16 #else\r
17         #define __ORTE_DLL_NAME         "orte.dll"\r
18 #endif\r
19 \r
20 struct __ORTE_DLL __orte;\r
21 \r
22 static const LPCSTR orteFnNames[] = {\r
23   "ORTEInit",\r
24   "ORTEDomainStart",\r
25   "ORTEDomainPropDefaultGet",\r
26   "ORTEDomainInitEvents",\r
27   "ORTEDomainAppCreate",\r
28   "ORTEDomainAppDestroy",\r
29   "ORTEDomainAppSubscriptionPatternAdd",\r
30   "ORTEDomainAppSubscriptionPatternRemove",\r
31   "ORTEDomainAppSubscriptionPatternDestroy",\r
32   "ORTEDomainMgrCreate",\r
33   "ORTEDomainMgrDestroy",\r
34   "ORTEPublicationCreate",\r
35   "ORTEPublicationDestroy",\r
36   "ORTEPublicationPropertiesGet",\r
37   "ORTEPublicationPropertiesSet",\r
38   "ORTEPublicationWaitForSubscriptions",\r
39   "ORTEPublicationGetStatus",\r
40   "ORTEPublicationSend",\r
41   "ORTEPublicationSendEx",\r
42   "ORTESubscriptionCreate",\r
43   "ORTESubscriptionDestroy",\r
44   "ORTESubscriptionPropertiesGet",\r
45   "ORTESubscriptionPropertiesSet",\r
46   "ORTESubscriptionWaitForPublications",\r
47   "ORTESubscriptionGetStatus",\r
48   "ORTESubscriptionPull",\r
49   "ORTETypeRegisterAdd",\r
50   "ORTETypeRegisterDestroyAll",\r
51   "ORTEVerbositySetOptions",\r
52   "ORTEVerbositySetLogFile",\r
53   "ORTESleepMs",\r
54   "IPAddressToString",\r
55   "StringToIPAddress",\r
56   "NtpTimeToStringMs",\r
57   "NtpTimeToStringUs"\r
58 };\r
59 \r
60 DWORD\r
61 GetProcAddresses(\r
62   HINSTANCE hInst,\r
63   FARPROC *functionTable,\r
64   const LPCSTR *names,\r
65   unsigned count\r
66   )\r
67 {\r
68   FARPROC *pfnMax = functionTable + count;\r
69 \r
70   while (functionTable < pfnMax) {\r
71     *functionTable = GetProcAddress(hInst, *names);\r
72     if (!*functionTable)\r
73       return GetLastError();\r
74     ++functionTable;\r
75     ++names;\r
76   }\r
77 \r
78   return ERROR_SUCCESS;\r
79 }\r
80 \r
81 #if 0\r
82 #define ORTE_GET_PROC_ADDRESS(symbol)   __orte.apis.symbol = (PFN_ ## symbol)GetProcAddress(__orte.hInstance, # symbol)\r
83 \r
84 int\r
85 SomePointerNull(FARPROC *functionTable, unsigned count)\r
86 {\r
87   FARPROC *max = functionTable + count;\r
88 \r
89   while (functionTable < max) {\r
90     if (*functionTable == NULL)\r
91       return 1;\r
92     ++functionTable;\r
93   }\r
94 \r
95   return 0;\r
96 }\r
97 #endif\r
98 \r
99 DWORD\r
100 __ORTEDllLoad(void)\r
101 {\r
102   if (!__orte.cLoads && !__orte.fLoadTried) {\r
103     __orte.fLoadTried = 1;\r
104 \r
105     __orte.hInstance = LoadLibrary(__ORTE_DLL_NAME);\r
106 \r
107     if (__orte.hInstance) {\r
108 \r
109       ASSERT(sizeof(struct __ORTE_APIS) / sizeof(FARPROC) == COUNTOF(orteFnNames));\r
110 \r
111       __orte.dwResult = GetProcAddresses(\r
112         __orte.hInstance,\r
113         (FARPROC *)&__orte.apis,\r
114         orteFnNames,\r
115         COUNTOF(orteFnNames));\r
116 \r
117       if (__orte.dwResult != ERROR_SUCCESS) {\r
118         FreeLibrary(__orte.hInstance);\r
119         __orte.hInstance = NULL;\r
120       } else {\r
121         __orte.dwResult = ERROR_SUCCESS;\r
122       }\r
123     } else {\r
124       __orte.dwResult = GetLastError();\r
125     }\r
126   }\r
127 \r
128   if (__orte.dwResult == ERROR_SUCCESS)\r
129     InterlockedIncrement(&__orte.cLoads);\r
130 \r
131   return __orte.dwResult;\r
132 }\r
133 \r
134 DWORD\r
135 __ORTEInit(void)\r
136 {\r
137   DWORD res = __ORTEDllLoad();\r
138 \r
139   if (res == ERROR_SUCCESS)\r
140     __orte.apis.pfnORTEInit();\r
141 \r
142   return res;\r
143 }\r