0
|
1 |
/*
|
|
2 |
* Copyright (c) 2004-2005 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
1
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
0
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
/* NmitShared/src/native */
|
|
20 |
#include "../../NmitShared/src/native/slib/include/s_mutex.h"
|
|
21 |
#include "../../NmitShared/src/native/xrpc/include/xrpc.h"
|
|
22 |
#include "../../NmitShared/src/native/xrpc/xreg/include/xregapi.h"
|
|
23 |
|
|
24 |
/* XRPC Runtime API */
|
|
25 |
#include "xrpcrt.h"
|
|
26 |
|
|
27 |
/* Global data */
|
|
28 |
static Mutex xrpcrt_mutex;
|
|
29 |
static XRpcServer * xrpcrt_server;
|
|
30 |
static XRpcRegistry * xrpcrt_registry;
|
|
31 |
static XRpcPort xrpcrt_port;
|
|
32 |
|
|
33 |
/**
|
|
34 |
* Returns one and only instance of XRpcServer. This instance is created
|
|
35 |
* on demand when you first time call this function.
|
|
36 |
*/
|
|
37 |
XRpcServer * XRPC_API XRPCRT_Server()
|
|
38 |
{
|
|
39 |
if (!xrpcrt_server) {
|
|
40 |
MUTEX_Lock(&xrpcrt_mutex);
|
|
41 |
if (!xrpcrt_server) {
|
|
42 |
xrpcrt_server = XRPC_CreateServer(NULL);
|
|
43 |
}
|
|
44 |
MUTEX_Unlock(&xrpcrt_mutex);
|
|
45 |
}
|
|
46 |
return xrpcrt_server;
|
|
47 |
}
|
|
48 |
|
|
49 |
/**
|
|
50 |
* Returns the port on which XRPC server is listening.
|
|
51 |
*/
|
|
52 |
XRpcPort XRPC_API XRPCRT_ServerPort()
|
|
53 |
{
|
|
54 |
if (!xrpcrt_port) {
|
|
55 |
XRpcServer * server = XRPCRT_Server();
|
|
56 |
if (server) {
|
|
57 |
MUTEX_Lock(&xrpcrt_mutex);
|
|
58 |
if (!xrpcrt_port) {
|
|
59 |
xrpcrt_port = XRPC_ServerSpawn(xrpcrt_server, 0);
|
|
60 |
}
|
|
61 |
MUTEX_Unlock(&xrpcrt_mutex);
|
|
62 |
}
|
|
63 |
}
|
|
64 |
return xrpcrt_port;
|
|
65 |
}
|
|
66 |
|
|
67 |
/**
|
|
68 |
* Returns one and only instance of XRpcRegistry. This instance is created
|
|
69 |
* on demand when you first time call this function.
|
|
70 |
*/
|
|
71 |
XRpcRegistry * XRPC_API XRPCRT_Registry()
|
|
72 |
{
|
|
73 |
if (!xrpcrt_registry) {
|
|
74 |
MUTEX_Lock(&xrpcrt_mutex);
|
|
75 |
if (!xrpcrt_registry) {
|
|
76 |
xrpcrt_registry = XREG_CreateRegistry(0,XRegTypeAny);
|
|
77 |
}
|
|
78 |
MUTEX_Unlock(&xrpcrt_mutex);
|
|
79 |
}
|
|
80 |
return xrpcrt_registry;
|
|
81 |
}
|
|
82 |
|
|
83 |
/**
|
|
84 |
* Global initialization
|
|
85 |
*/
|
|
86 |
STATIC void XRPCRT_Init()
|
|
87 |
{
|
|
88 |
XRPC_Init();
|
|
89 |
MUTEX_Init(&xrpcrt_mutex);
|
|
90 |
xrpcrt_registry = NULL;
|
|
91 |
xrpcrt_server = NULL;
|
|
92 |
xrpcrt_port = 0;
|
|
93 |
}
|
|
94 |
|
|
95 |
/**
|
|
96 |
* DLL entry point
|
|
97 |
*/
|
|
98 |
BOOL
|
|
99 |
WINAPI DllMain(
|
|
100 |
HINSTANCE hinst, /* handle to the DLL module */
|
|
101 |
DWORD reason, /* reason for calling function */
|
|
102 |
LPVOID reserved) /* reserved */
|
|
103 |
{
|
|
104 |
TCHAR path[MAX_PATH+1];
|
|
105 |
switch (reason) {
|
|
106 |
case DLL_PROCESS_ATTACH:
|
|
107 |
TRACE("XRPCRT: Loading...\n");
|
|
108 |
/* Add reference to ourselves so that we never get unloaded */
|
|
109 |
path[GetModuleFileName(hinst, path, MAX_PATH)] = 0;
|
|
110 |
VERIFY(LoadLibrary(path));
|
|
111 |
XRPCRT_Init();
|
|
112 |
break;
|
|
113 |
case DLL_PROCESS_DETACH:
|
|
114 |
/* We only get here when the process is exiting */
|
|
115 |
TRACE("XRPCRT: Unloading...\n");
|
|
116 |
break;
|
|
117 |
}
|
|
118 |
return TRUE;
|
|
119 |
}
|