Index: ceee/ie/broker/broker_rpc_client.cc |
=================================================================== |
--- ceee/ie/broker/broker_rpc_client.cc (revision 0) |
+++ ceee/ie/broker/broker_rpc_client.cc (revision 0) |
@@ -0,0 +1,113 @@ |
+// 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 Client implementation. |
+ |
+#include "ceee/ie/broker/broker_rpc_client.h" |
+ |
+#include "base/lock.h" |
+#include "base/logging.h" |
+#include "broker_rpc_lib.h" |
+#include "ceee/ie/broker/broker_rpc_utils.h" |
+ |
+BrokerRpcClient::BrokerRpcClient() : context_(0), binding_handle_(NULL) { |
+} |
+ |
+BrokerRpcClient::~BrokerRpcClient() { |
+ Disconnect(); |
+} |
+ |
+int HandleRpcException(unsigned int rpc_exception_code) { |
+ switch (rpc_exception_code) { |
+ case STATUS_ACCESS_VIOLATION: |
+ case STATUS_DATATYPE_MISALIGNMENT: |
+ case STATUS_PRIVILEGED_INSTRUCTION: |
+ case STATUS_BREAKPOINT: |
+ case STATUS_STACK_OVERFLOW: |
+ case STATUS_IN_PAGE_ERROR: |
+ case STATUS_GUARD_PAGE_VIOLATION: |
+ return EXCEPTION_CONTINUE_SEARCH; |
+ default: |
+ break; |
+ } |
+ return EXCEPTION_EXECUTE_HANDLER; |
+} |
+ |
+void BrokerRpcClient::LockContext() { |
+ RpcTryExcept { |
+ context_ = BrokerRpcClient_Connect(binding_handle_); |
+ } RpcExcept(HandleRpcException(RpcExceptionCode())) { |
+ LOG(ERROR) << "RPC error: " << RpcExceptionCode(); |
+ } RpcEndExcept |
+} |
+ |
+void BrokerRpcClient::ReleaseContext() { |
+ RpcTryExcept { |
+ BrokerRpcClient_Disconnect(binding_handle_, &context_); |
+ } RpcExcept(HandleRpcException(RpcExceptionCode())) { |
+ LOG(ERROR) << "RPC error: " << RpcExceptionCode(); |
+ } RpcEndExcept |
+} |
+ |
+bool BrokerRpcClient::Connect() { |
+ if (is_connected()) |
+ return true; |
+ |
+ std::wstring end_point = GetRpcEndPointAddress(); |
+ std::wstring protocol = kRpcProtocol; |
+ DCHECK(!protocol.empty()); |
+ DCHECK(!end_point.empty()); |
Sigurður Ásgeirsson
2010/11/11 19:30:35
this function, and our code in general, should log
Vitaly Buka corp
2010/11/11 23:12:10
There is nothing to log in this place. It is just
|
+ if (protocol.empty() || end_point.empty()) |
+ return false; |
+ |
+ // TODO(vitalybuka@google.com): There's no guarantee (aside from name |
+ // uniqueness) that it will connect to an endpoint created by the same user. |
Sigurður Ásgeirsson
2010/11/11 19:30:35
The missing invocation is RpcBindingSetAuthInfoEx.
Vitaly Buka corp
2010/11/11 23:12:10
Done.
|
+ LOG(INFO) << "Connecting to RPC server. Endpoint: " << end_point; |
+ RPC_WSTR string_binding = NULL; |
+ RPC_STATUS status = RpcStringBindingCompose( |
+ NULL, |
+ reinterpret_cast<RPC_WSTR>(&protocol[0]), |
+ NULL, |
+ reinterpret_cast<RPC_WSTR>(&end_point[0]), |
+ NULL, |
+ &string_binding); |
+ |
+ DCHECK(RPC_S_OK == status); |
+ if (RPC_S_OK == status) { |
+ status = RpcBindingFromStringBinding(string_binding, &binding_handle_); |
+ RpcStringFree(&string_binding); |
+ DCHECK(RPC_S_OK == status); |
+ if (RPC_S_OK == status) { |
+ status = RpcEpResolveBinding(binding_handle_, |
+ BrokerRpcClient_Broker_v1_1_c_ifspec); |
+ DCHECK(RPC_S_OK == status); |
+ if (RPC_S_OK == status) { |
+ LOG(INFO) << "RPC client is connected. Endpoint: " << end_point; |
+ LockContext(); |
+ } |
+ } |
+ } |
+ if (!is_connected()) |
+ Disconnect(); |
+ return is_connected(); |
+} |
+ |
+void BrokerRpcClient::Disconnect() { |
+ if (context_ != NULL) |
+ ReleaseContext(); |
+ if (binding_handle_ != NULL) { |
+ RPC_STATUS status = RpcBindingFree(&binding_handle_); |
+ DCHECK(RPC_S_OK == status); |
+ } |
+} |
+ |
+bool BrokerRpcClient::FireEvent(BSTR event_name, BSTR event_args) { |
+ RpcTryExcept { |
+ BrokerRpcClient_FireEvent(binding_handle_, event_name, event_args); |
+ return true; |
+ } RpcExcept(HandleRpcException(RpcExceptionCode())) { |
+ LOG(ERROR) << "RPC error: " << RpcExceptionCode(); |
+ } RpcEndExcept |
+ return false; |
+} |
Property changes on: ceee\ie\broker\broker_rpc_client.cc |
___________________________________________________________________ |
Added: svn:eol-style |
+ LF |