Chromium Code Reviews| 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,126 @@ |
| +// 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), |
| + current_thread_(GetCurrentThreadId()) { |
|
Sigurður Ásgeirsson
2010/11/12 14:40:24
ceee likes to prefix win32 API invocations with ::
Vitaly Buka corp
2010/11/12 20:58:48
Done.
|
| +} |
| + |
| +BrokerRpcServer::~BrokerRpcServer() { |
| + DCHECK(current_thread_ == GetCurrentThreadId()); |
| + Stop(); |
| +} |
| + |
| +bool BrokerRpcServer::Start() { |
| + DCHECK(current_thread_ == GetCurrentThreadId()); |
| + |
| + 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; |
| + // Tell RPC runtime to use local interprocess communication for given |
| + // end point. |
| + RPC_STATUS status = RpcServerUseProtseqEp( |
| + reinterpret_cast<RPC_WSTR>(&protocol[0]), |
| + RPC_C_PROTSEQ_MAX_REQS_DEFAULT, |
| + reinterpret_cast<RPC_WSTR>(&end_point[0]), |
| + NULL); |
| + LOG_IF(ERROR, RPC_S_OK != status && RPC_S_DUPLICATE_ENDPOINT != status) << |
| + "Failed to set protocol for RPC end point. RPC_STATUS=0x" << |
| + std::hex << status; |
| + if (RPC_S_OK == status || RPC_S_DUPLICATE_ENDPOINT == status) { |
| + // Register RPC interface with the RPC runtime. |
| + status = RpcServerRegisterIfEx(BrokerRpcServer_CeeeBroker_v1_1_s_ifspec, |
| + NULL, NULL, 0, RPC_C_LISTEN_MAX_CALLS_DEFAULT, NULL); |
| + LOG_IF(ERROR, RPC_S_OK != status) << |
| + "Failed to register RPC interface. RPC_STATUS=0x" << std::hex << status; |
|
Sigurður Ásgeirsson
2010/11/12 14:40:24
As RPC error codes are windows errors, you can log
Vitaly Buka corp
2010/11/12 20:58:48
Done.
|
| + if (RPC_S_OK == status) { |
| + // Start listen for RPC calls. |
| + status = RpcServerListen(1, RPC_C_LISTEN_MAX_CALLS_DEFAULT, TRUE); |
| + LOG_IF(ERROR, RPC_S_OK != status) << |
| + "Failed to start listening. RPC_STATUS=0x" << std::hex << status; |
| + if (RPC_S_OK == status) { |
| + LOG(INFO) << "RPC server is started. Endpoint: " << end_point; |
| + is_started_ = true; |
| + } |
| + } |
| + } |
| + if (!is_started()) |
| + Stop(); |
| + |
| + return is_started(); |
| +} |
| + |
| +bool BrokerRpcServer::Stop() { |
| + DCHECK(current_thread_ == GetCurrentThreadId()); |
| + is_started_ = false; |
| + // Stop server listening for PRC. |
|
Sigurður Ásgeirsson
2010/11/12 14:40:24
PRC->RPC :)
Vitaly Buka corp
2010/11/12 20:58:48
Done.
|
| + RPC_STATUS status = RpcMgmtStopServerListening(NULL); |
| + LOG_IF(WARNING, RPC_S_OK != status) << |
| + "Failed to stop listening. RPC_STATUS=0x" << std::hex << status; |
| + // Wait server stops listening threads. |
|
Sigurður Ásgeirsson
2010/11/12 14:40:24
Wait while?
Vitaly Buka corp
2010/11/12 20:58:48
Done.
|
| + status = RpcMgmtWaitServerListen(); |
| + LOG_IF(WARNING, RPC_S_OK != status) << |
| + "Failed to wait server listen. RPC_STATUS=0x" << std::hex << status; |
| + // Unregister RPC interface. |
| + status = RpcServerUnregisterIf( |
| + BrokerRpcServer_CeeeBroker_v1_1_s_ifspec, NULL, FALSE); |
| + LOG_IF(WARNING, RPC_S_OK != status) << |
| + "Failed to unregister interface. RPC_STATUS=0x" << std::hex << status; |
| + return RPC_S_OK == status; |
| +} |
| + |
| +bool BrokerRpcServer::is_started() const { |
| + DCHECK(current_thread_ == GetCurrentThreadId()); |
| + return is_started_; |
| +} |
| + |
| +BrokerContextHandle BrokerRpcServer_Connect(handle_t binding_handle) { |
| + // TODO(vitalybuka@google.com): Add client identity check. |
| + static long current_context = 0; |
| + 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); |
|
Sigurður Ásgeirsson
2010/11/12 14:40:24
Hold on, so there's currently no association to a
Vitaly Buka corp
2010/11/12 20:58:48
Please explain what do you mean.
is this about unr
Sigurður Ásgeirsson
2010/11/12 21:10:15
Well, when one of the RPC clients winks out of exi
|
| + 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 |