|
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 Client implementation. | |
6 | |
7 #include "ceee/ie/broker/broker_rpc_client.h" | |
8 | |
9 #include "base/lock.h" | |
10 #include "base/logging.h" | |
11 #include "broker_rpc_lib.h" | |
12 #include "ceee/ie/broker/broker_rpc_utils.h" | |
13 | |
14 BrokerRpcClient::BrokerRpcClient() : context_(0), binding_handle_(NULL) { | |
15 } | |
16 | |
17 BrokerRpcClient::~BrokerRpcClient() { | |
18 Disconnect(); | |
19 } | |
20 | |
21 int HandleRpcException(unsigned int rpc_exception_code) { | |
22 switch (rpc_exception_code) { | |
23 case STATUS_ACCESS_VIOLATION: | |
24 case STATUS_DATATYPE_MISALIGNMENT: | |
25 case STATUS_PRIVILEGED_INSTRUCTION: | |
26 case STATUS_BREAKPOINT: | |
27 case STATUS_STACK_OVERFLOW: | |
28 case STATUS_IN_PAGE_ERROR: | |
29 case STATUS_GUARD_PAGE_VIOLATION: | |
30 return EXCEPTION_CONTINUE_SEARCH; | |
31 default: | |
32 break; | |
33 } | |
34 return EXCEPTION_EXECUTE_HANDLER; | |
35 } | |
36 | |
37 void BrokerRpcClient::LockContext() { | |
38 RpcTryExcept { | |
39 context_ = BrokerRpcClient_Connect(binding_handle_); | |
40 } RpcExcept(HandleRpcException(RpcExceptionCode())) { | |
41 LOG(ERROR) << "RPC error: " << RpcExceptionCode(); | |
42 } RpcEndExcept | |
43 } | |
44 | |
45 void BrokerRpcClient::ReleaseContext() { | |
46 RpcTryExcept { | |
47 BrokerRpcClient_Disconnect(binding_handle_, &context_); | |
48 } RpcExcept(HandleRpcException(RpcExceptionCode())) { | |
49 LOG(ERROR) << "RPC error: " << RpcExceptionCode(); | |
50 } RpcEndExcept | |
51 } | |
52 | |
53 bool BrokerRpcClient::Connect() { | |
54 if (is_connected()) | |
55 return true; | |
56 | |
57 std::wstring end_point = GetRpcEndPointAddress(); | |
58 std::wstring protocol = kRpcProtocol; | |
59 DCHECK(!protocol.empty()); | |
60 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
| |
61 if (protocol.empty() || end_point.empty()) | |
62 return false; | |
63 | |
64 // TODO(vitalybuka@google.com): There's no guarantee (aside from name | |
65 // 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.
| |
66 LOG(INFO) << "Connecting to RPC server. Endpoint: " << end_point; | |
67 RPC_WSTR string_binding = NULL; | |
68 RPC_STATUS status = RpcStringBindingCompose( | |
69 NULL, | |
70 reinterpret_cast<RPC_WSTR>(&protocol[0]), | |
71 NULL, | |
72 reinterpret_cast<RPC_WSTR>(&end_point[0]), | |
73 NULL, | |
74 &string_binding); | |
75 | |
76 DCHECK(RPC_S_OK == status); | |
77 if (RPC_S_OK == status) { | |
78 status = RpcBindingFromStringBinding(string_binding, &binding_handle_); | |
79 RpcStringFree(&string_binding); | |
80 DCHECK(RPC_S_OK == status); | |
81 if (RPC_S_OK == status) { | |
82 status = RpcEpResolveBinding(binding_handle_, | |
83 BrokerRpcClient_Broker_v1_1_c_ifspec); | |
84 DCHECK(RPC_S_OK == status); | |
85 if (RPC_S_OK == status) { | |
86 LOG(INFO) << "RPC client is connected. Endpoint: " << end_point; | |
87 LockContext(); | |
88 } | |
89 } | |
90 } | |
91 if (!is_connected()) | |
92 Disconnect(); | |
93 return is_connected(); | |
94 } | |
95 | |
96 void BrokerRpcClient::Disconnect() { | |
97 if (context_ != NULL) | |
98 ReleaseContext(); | |
99 if (binding_handle_ != NULL) { | |
100 RPC_STATUS status = RpcBindingFree(&binding_handle_); | |
101 DCHECK(RPC_S_OK == status); | |
102 } | |
103 } | |
104 | |
105 bool BrokerRpcClient::FireEvent(BSTR event_name, BSTR event_args) { | |
106 RpcTryExcept { | |
107 BrokerRpcClient_FireEvent(binding_handle_, event_name, event_args); | |
108 return true; | |
109 } RpcExcept(HandleRpcException(RpcExceptionCode())) { | |
110 LOG(ERROR) << "RPC error: " << RpcExceptionCode(); | |
111 } RpcEndExcept | |
112 return false; | |
113 } | |
OLD | NEW |