Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(307)

Side by Side Diff: ceee/ie/broker/broker_rpc_client.cc

Issue 4989002: Firing event to broker without worker thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ceee/ie/broker/broker_rpc_client.h ('k') | ceee/ie/broker/broker_rpc_lib.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // Broker RPC Client implementation. 5 // Broker RPC Client implementation.
6 6
7 #include "ceee/ie/broker/broker_rpc_client.h" 7 #include "ceee/ie/broker/broker_rpc_client.h"
8 8
9 #include <atlbase.h>
9 #include "base/lock.h" 10 #include "base/lock.h"
10 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "broker_lib.h" // NOLINT
11 #include "broker_rpc_lib.h" // NOLINT 13 #include "broker_rpc_lib.h" // NOLINT
12 #include "ceee/common/com_utils.h" 14 #include "ceee/common/com_utils.h"
13 #include "ceee/ie/broker/broker_rpc_utils.h" 15 #include "ceee/ie/broker/broker_rpc_utils.h"
14 16
15 BrokerRpcClient::BrokerRpcClient() : context_(0), binding_handle_(NULL) { 17 BrokerRpcClient::BrokerRpcClient() : context_(0), binding_handle_(NULL) {
16 } 18 }
17 19
18 BrokerRpcClient::~BrokerRpcClient() { 20 BrokerRpcClient::~BrokerRpcClient() {
19 Disconnect(); 21 Disconnect();
20 } 22 }
(...skipping 27 matching lines...) Expand all
48 } 50 }
49 51
50 void BrokerRpcClient::ReleaseContext() { 52 void BrokerRpcClient::ReleaseContext() {
51 RpcTryExcept { 53 RpcTryExcept {
52 BrokerRpcClient_Disconnect(binding_handle_, &context_); 54 BrokerRpcClient_Disconnect(binding_handle_, &context_);
53 } RpcExcept(HandleRpcException(RpcExceptionCode())) { 55 } RpcExcept(HandleRpcException(RpcExceptionCode())) {
54 LogRpcException("RPC error in ReleaseContext", RpcExceptionCode()); 56 LogRpcException("RPC error in ReleaseContext", RpcExceptionCode());
55 } RpcEndExcept 57 } RpcEndExcept
56 } 58 }
57 59
58 bool BrokerRpcClient::Connect() { 60 HRESULT BrokerRpcClient::StartServer() {
61 // TODO(vitalybuka@google.com): Start broker without COM after the last
62 // COM interface is removed.
63 CComPtr<ICeeeBrokerRegistrar> broker;
64 HRESULT hr = broker.CoCreateInstance(CLSID_CeeeBroker);
65 LOG_IF(ERROR, FAILED(hr)) << "Failed to create broker. " << com::LogHr(hr);
66 return hr;
67 }
68
69 HRESULT BrokerRpcClient::Connect() {
59 if (is_connected()) 70 if (is_connected())
60 return true; 71 return S_OK;
61 72
62 std::wstring end_point = GetRpcEndPointAddress(); 73 std::wstring end_point = GetRpcEndPointAddress();
63 std::wstring protocol = kRpcProtocol; 74 std::wstring protocol = kRpcProtocol;
64 DCHECK(!protocol.empty()); 75 DCHECK(!protocol.empty());
65 DCHECK(!end_point.empty()); 76 DCHECK(!end_point.empty());
66 if (protocol.empty() || end_point.empty()) 77 if (protocol.empty() || end_point.empty())
67 return false; 78 return RPC_E_FAULT;
68 79
69 // TODO(vitalybuka@google.com): There's no guarantee (aside from name 80 // TODO(vitalybuka@google.com): There's no guarantee (aside from name
70 // uniqueness) that it will connect to an endpoint created by the same user. 81 // uniqueness) that it will connect to an endpoint created by the same user.
71 // Hint: The missing invocation is RpcBindingSetAuthInfoEx. 82 // Hint: The missing invocation is RpcBindingSetAuthInfoEx.
72 LOG(INFO) << "Connecting to RPC server. Endpoint: " << end_point; 83 LOG(INFO) << "Connecting to RPC server. Endpoint: " << end_point;
73 RPC_WSTR string_binding = NULL; 84 RPC_WSTR string_binding = NULL;
74 // Create binding string with given protocol and end point. 85 // Create binding string with given protocol and end point.
75 RPC_STATUS status = ::RpcStringBindingCompose( 86 RPC_STATUS status = ::RpcStringBindingCompose(
76 NULL, 87 NULL,
77 reinterpret_cast<RPC_WSTR>(&protocol[0]), 88 reinterpret_cast<RPC_WSTR>(&protocol[0]),
78 NULL, 89 NULL,
79 reinterpret_cast<RPC_WSTR>(&end_point[0]), 90 reinterpret_cast<RPC_WSTR>(&end_point[0]),
80 NULL, 91 NULL,
81 &string_binding); 92 &string_binding);
82 LOG_IF(ERROR, RPC_S_OK != status) << 93 LOG_IF(ERROR, RPC_S_OK != status) <<
83 "Failed to compose binding string. RPC_STATUS=0x" << com::LogWe(status); 94 "Failed to compose binding string. RPC_STATUS=0x" << com::LogWe(status);
84 95
85 if (RPC_S_OK == status) { 96 if (RPC_S_OK == status) {
86 // Create binding from just generated binding string. Binding handle should 97 // Create binding from just generated binding string. Binding handle should
87 // used for PRC calls. 98 // used for PRC calls.
88 status = ::RpcBindingFromStringBinding(string_binding, &binding_handle_); 99 status = ::RpcBindingFromStringBinding(string_binding, &binding_handle_);
89 LOG_IF(ERROR, RPC_S_OK != status) << 100 LOG_IF(ERROR, RPC_S_OK != status) <<
90 "Failed to bind. RPC_STATUS=0x" << com::LogWe(status); 101 "Failed to bind. RPC_STATUS=0x" << com::LogWe(status);
91 ::RpcStringFree(&string_binding); 102 ::RpcStringFree(&string_binding);
92 if (RPC_S_OK == status) { 103 if (RPC_S_OK == status) {
93 LOG(INFO) << "RPC client is connected. Endpoint: " << end_point; 104 LOG(INFO) << "RPC client is connected. Endpoint: " << end_point;
94 LockContext(); 105 LockContext();
95 } 106 }
96 } 107 }
97 if (!is_connected()) 108 if (!is_connected()) {
98 Disconnect(); 109 Disconnect();
99 return is_connected(); 110 return RPC_E_FAULT;
111 }
112 return S_OK;
100 } 113 }
101 114
102 void BrokerRpcClient::Disconnect() { 115 void BrokerRpcClient::Disconnect() {
103 if (context_ != NULL) 116 if (context_ != NULL)
104 ReleaseContext(); 117 ReleaseContext();
105 if (binding_handle_ != NULL) { 118 if (binding_handle_ != NULL) {
106 RPC_STATUS status = ::RpcBindingFree(&binding_handle_); 119 RPC_STATUS status = ::RpcBindingFree(&binding_handle_);
107 LOG_IF(WARNING, RPC_S_OK != status) << 120 LOG_IF(WARNING, RPC_S_OK != status) <<
108 "Failed to unbind. RPC_STATUS=0x" << com::LogWe(status); 121 "Failed to unbind. RPC_STATUS=0x" << com::LogWe(status);
109 } 122 }
110 } 123 }
111 124
112 bool BrokerRpcClient::FireEvent(BSTR event_name, BSTR event_args) { 125 HRESULT BrokerRpcClient::FireEvent(const char* event_name,
126 const char* event_args) {
113 RpcTryExcept { 127 RpcTryExcept {
114 BrokerRpcClient_FireEvent(binding_handle_, event_name, event_args); 128 BrokerRpcClient_FireEvent(binding_handle_, event_name, event_args);
115 return true; 129 return S_OK;
116 } RpcExcept(HandleRpcException(RpcExceptionCode())) { 130 } RpcExcept(HandleRpcException(RpcExceptionCode())) {
117 LogRpcException("RPC error in FireEvent", RpcExceptionCode()); 131 LogRpcException("RPC error in FireEvent", RpcExceptionCode());
118 } RpcEndExcept 132 } RpcEndExcept
119 return false; 133 return RPC_E_FAULT;
120 } 134 }
OLDNEW
« no previous file with comments | « ceee/ie/broker/broker_rpc_client.h ('k') | ceee/ie/broker/broker_rpc_lib.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698