|
OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 // | |
5 // Broker RPC Server implementation. | |
6 | |
7 #include "ceee/ie/broker/broker_rpc_server.h" | |
8 | |
9 #include "base/logging.h" | |
10 #include "base/win_util.h" | |
11 #include "broker_rpc_lib.h" | |
12 #include "ceee/ie/broker/broker_module_util.h" | |
13 #include "ceee/ie/broker/broker_rpc_utils.h" | |
14 #include "ceee/ie/broker/chrome_postman.h" | |
15 | |
16 BrokerRpcServer::BrokerRpcServer() : is_started_(false) { | |
17 } | |
18 | |
19 BrokerRpcServer::~BrokerRpcServer() { | |
20 Stop(); | |
21 } | |
22 | |
23 bool BrokerRpcServer::Start() { | |
24 if (is_started()) | |
25 return true; | |
26 | |
27 std::wstring end_point = GetRpcEndPointAddress(); | |
28 std::wstring protocol = kRpcProtocol; | |
29 DCHECK(!protocol.empty()); | |
30 DCHECK(!end_point.empty()); | |
31 if (protocol.empty() || end_point.empty()) | |
32 return false; | |
33 | |
34 LOG(INFO) << "RPC server is starting. Endpoint: " << end_point; | |
35 RPC_STATUS status = RpcServerUseProtseqEp( | |
Sigurður Ásgeirsson
2010/11/11 19:30:35
since use of RPC is so rare, can I ask you to spri
Vitaly Buka corp
2010/11/11 23:12:10
Done.
| |
36 reinterpret_cast<RPC_WSTR>(&protocol[0]), | |
37 RPC_C_PROTSEQ_MAX_REQS_DEFAULT, | |
38 reinterpret_cast<RPC_WSTR>(&end_point[0]), | |
39 NULL); | |
40 DCHECK(RPC_S_OK == status || RPC_S_DUPLICATE_ENDPOINT == status); | |
41 | |
42 if (RPC_S_OK == status || RPC_S_DUPLICATE_ENDPOINT == status) { | |
43 status = RpcServerRegisterIfEx(BrokerRpcServer_Broker_v1_1_s_ifspec, NULL, | |
44 NULL, 0, RPC_C_LISTEN_MAX_CALLS_DEFAULT, NULL); | |
45 DCHECK(RPC_S_OK == status); | |
46 | |
47 if (RPC_S_OK == status) { | |
48 status = RpcServerListen(1, RPC_C_LISTEN_MAX_CALLS_DEFAULT, TRUE); | |
49 DCHECK(RPC_S_OK == status); | |
50 | |
51 if (RPC_S_OK == status) { | |
52 LOG(INFO) << "RPC server is started. Endpoint: " << end_point; | |
53 is_started_ = true; | |
54 } | |
55 } | |
56 } | |
57 | |
58 return is_started(); | |
59 } | |
60 | |
61 bool BrokerRpcServer::Stop() { | |
62 if (!is_started()) | |
63 return true; | |
64 is_started_ = false; | |
65 RPC_STATUS status = RpcMgmtStopServerListening(NULL); | |
Sigurður Ásgeirsson
2010/11/11 19:30:35
... same here ...
Vitaly Buka corp
2010/11/11 23:12:10
Done.
| |
66 DCHECK(RPC_S_OK == status); | |
67 status = RpcMgmtWaitServerListen(); | |
68 DCHECK(RPC_S_OK == status); | |
69 status = RpcServerUnregisterIf( | |
70 BrokerRpcServer_Broker_v1_1_s_ifspec, NULL, FALSE); | |
71 DCHECK(RPC_S_OK == status); | |
72 return RPC_S_OK == status; | |
73 } | |
74 | |
75 BrokerContextHandle BrokerRpcServer_Connect( | |
76 handle_t binding_handle) { | |
77 static long current_context = 0; | |
Sigurður Ásgeirsson
2010/11/11 19:30:35
I imagine this'd be the place to add the client id
Vitaly Buka corp
2010/11/11 23:12:10
Done.
| |
78 ceee_module_util::LockModule(); | |
79 return reinterpret_cast<void*>(InterlockedIncrement(¤t_context)); | |
80 } | |
81 | |
82 void BrokerRpcServer_Disconnect( | |
83 handle_t binding_handle, | |
84 BrokerContextHandle* context) { | |
85 DCHECK(context != NULL); | |
86 if (context) | |
87 *context = NULL; | |
88 ceee_module_util::UnlockModule(); | |
89 } | |
90 | |
91 // Called when client process terminated without releasing context handle. | |
92 void __RPC_USER BrokerContextHandle_rundown(BrokerContextHandle context) { | |
93 DCHECK(context != NULL); | |
94 ceee_module_util::UnlockModule(); | |
95 } | |
96 | |
97 void BrokerRpcServer_FireEvent( | |
98 handle_t binding_handle, | |
99 BSTR event_name, | |
100 BSTR event_args) { | |
101 DCHECK(ChromePostman::GetInstance()); | |
102 if (ChromePostman::GetInstance()) | |
103 ChromePostman::GetInstance()->FireEvent(event_name, event_args); | |
104 } | |
OLD | NEW |