Index: ceee/ie/broker/broker_rpc_server.cc |
=================================================================== |
--- ceee/ie/broker/broker_rpc_server.cc (revision 0) |
+++ ceee/ie/broker/broker_rpc_server.cc (revision 0) |
@@ -0,0 +1,104 @@ |
+// Copyright (c) 2010 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+// |
+// Broker RPC Server implementation. |
+ |
+#include "ceee/ie/broker/broker_rpc_server.h" |
+ |
+#include "base/logging.h" |
+#include "base/win_util.h" |
+#include "broker_rpc_lib.h" |
+#include "ceee/ie/broker/broker_module_util.h" |
+#include "ceee/ie/broker/broker_rpc_utils.h" |
+#include "ceee/ie/broker/chrome_postman.h" |
+ |
+BrokerRpcServer::BrokerRpcServer() : is_started_(false) { |
+} |
+ |
+BrokerRpcServer::~BrokerRpcServer() { |
+ Stop(); |
+} |
+ |
+bool BrokerRpcServer::Start() { |
+ if (is_started()) |
+ return true; |
+ |
+ std::wstring end_point = GetRpcEndPointAddress(); |
+ std::wstring protocol = kRpcProtocol; |
+ DCHECK(!protocol.empty()); |
+ DCHECK(!end_point.empty()); |
+ if (protocol.empty() || end_point.empty()) |
+ return false; |
+ |
+ LOG(INFO) << "RPC server is starting. Endpoint: " << end_point; |
+ 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.
|
+ reinterpret_cast<RPC_WSTR>(&protocol[0]), |
+ RPC_C_PROTSEQ_MAX_REQS_DEFAULT, |
+ reinterpret_cast<RPC_WSTR>(&end_point[0]), |
+ NULL); |
+ DCHECK(RPC_S_OK == status || RPC_S_DUPLICATE_ENDPOINT == status); |
+ |
+ if (RPC_S_OK == status || RPC_S_DUPLICATE_ENDPOINT == status) { |
+ status = RpcServerRegisterIfEx(BrokerRpcServer_Broker_v1_1_s_ifspec, NULL, |
+ NULL, 0, RPC_C_LISTEN_MAX_CALLS_DEFAULT, NULL); |
+ DCHECK(RPC_S_OK == status); |
+ |
+ if (RPC_S_OK == status) { |
+ status = RpcServerListen(1, RPC_C_LISTEN_MAX_CALLS_DEFAULT, TRUE); |
+ DCHECK(RPC_S_OK == status); |
+ |
+ if (RPC_S_OK == status) { |
+ LOG(INFO) << "RPC server is started. Endpoint: " << end_point; |
+ is_started_ = true; |
+ } |
+ } |
+ } |
+ |
+ return is_started(); |
+} |
+ |
+bool BrokerRpcServer::Stop() { |
+ if (!is_started()) |
+ return true; |
+ is_started_ = false; |
+ 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.
|
+ DCHECK(RPC_S_OK == status); |
+ status = RpcMgmtWaitServerListen(); |
+ DCHECK(RPC_S_OK == status); |
+ status = RpcServerUnregisterIf( |
+ BrokerRpcServer_Broker_v1_1_s_ifspec, NULL, FALSE); |
+ DCHECK(RPC_S_OK == status); |
+ return RPC_S_OK == status; |
+} |
+ |
+BrokerContextHandle BrokerRpcServer_Connect( |
+ handle_t binding_handle) { |
+ 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.
|
+ ceee_module_util::LockModule(); |
+ return reinterpret_cast<void*>(InterlockedIncrement(¤t_context)); |
+} |
+ |
+void BrokerRpcServer_Disconnect( |
+ handle_t binding_handle, |
+ BrokerContextHandle* context) { |
+ DCHECK(context != NULL); |
+ if (context) |
+ *context = NULL; |
+ ceee_module_util::UnlockModule(); |
+} |
+ |
+// Called when client process terminated without releasing context handle. |
+void __RPC_USER BrokerContextHandle_rundown(BrokerContextHandle context) { |
+ DCHECK(context != NULL); |
+ ceee_module_util::UnlockModule(); |
+} |
+ |
+void BrokerRpcServer_FireEvent( |
+ handle_t binding_handle, |
+ BSTR event_name, |
+ BSTR event_args) { |
+ DCHECK(ChromePostman::GetInstance()); |
+ if (ChromePostman::GetInstance()) |
+ ChromePostman::GetInstance()->FireEvent(event_name, event_args); |
+} |
Property changes on: ceee\ie\broker\broker_rpc_server.cc |
___________________________________________________________________ |
Added: svn:eol-style |
+ LF |