OLD | NEW |
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. | 5 // Broker RPC Client. |
6 | 6 |
7 #ifndef CEEE_IE_BROKER_BROKER_RPC_CLIENT_H_ | 7 #ifndef CEEE_IE_BROKER_BROKER_RPC_CLIENT_H_ |
8 #define CEEE_IE_BROKER_BROKER_RPC_CLIENT_H_ | 8 #define CEEE_IE_BROKER_BROKER_RPC_CLIENT_H_ |
9 | 9 |
10 #include <wtypes.h> | 10 #include <wtypes.h> |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 | 12 |
| 13 struct IUnknown; |
13 // Interface for sending events. | 14 // Interface for sending events. |
14 class IEventSender { | 15 class IEventSender { |
15 public: | 16 public: |
16 virtual ~IEventSender() {} | 17 virtual ~IEventSender() {} |
17 virtual HRESULT FireEvent(const char* event_name, | 18 virtual HRESULT FireEvent(const char* event_name, |
18 const char* event_args) = 0; | 19 const char* event_args) = 0; |
19 }; | 20 }; |
20 | 21 |
21 | |
22 // Class provides communication with BrokerRpcServer. | 22 // Class provides communication with BrokerRpcServer. |
23 class BrokerRpcClient : public IEventSender { | 23 class BrokerRpcClient : public IEventSender { |
24 public: | 24 public: |
25 BrokerRpcClient(); | 25 // @param allow_restarts if true client will restart server if it is somehow |
| 26 // gone after successful connecting. Client restarts server one time after |
| 27 // each successful connecting. |
| 28 explicit BrokerRpcClient(bool allow_restarts); |
26 virtual ~BrokerRpcClient(); | 29 virtual ~BrokerRpcClient(); |
27 | 30 |
28 // Initialize connection with server. | 31 // Initialize connection with server. |
29 // @param start_server if true method will try to start server if it is | 32 // @param start_server if true method will try to start server if it is not |
30 // not started yet. Usually only tests pass false here. | 33 // started yet. Usually only tests pass false here. |
31 virtual HRESULT Connect(bool start_server); | 34 virtual HRESULT Connect(bool start_server); |
32 | 35 |
33 // Relese connection with server | 36 // Releases connection with server |
34 virtual void Disconnect(); | 37 virtual void Disconnect(); |
35 | 38 |
36 // Returns true if object ready for remote calls. | 39 // Returns true if object ready for remote calls. |
37 virtual bool is_connected() const { | 40 virtual bool is_connected() const { |
38 return context_ != NULL && binding_handle_ != NULL; | 41 return context_ != NULL && binding_handle_ != NULL; |
39 } | 42 } |
40 | 43 |
41 // @name Remote calls. | 44 // @name Remote calls. |
42 // @{ | 45 // @{ |
43 // Calls FireEvent on server side. | 46 // Calls FireEvent on server side. |
44 virtual HRESULT FireEvent(const char* event_name, const char* event_args); | 47 virtual HRESULT FireEvent(const char* event_name, const char* event_args); |
45 // Adds UMA to histograms on the server side. Either performance timings or | 48 // Adds UMA to histograms on the server side. Either performance timings or |
46 // generic histogram. | 49 // generic histogram. |
47 virtual HRESULT SendUmaHistogramTimes(const char* name, int sample); | 50 virtual HRESULT SendUmaHistogramTimes(const char* name, int sample); |
48 virtual HRESULT SendUmaHistogramData(const char* name, | 51 virtual HRESULT SendUmaHistogramData(const char* name, |
49 int sample, | 52 int sample, |
50 int min, | 53 int min, |
51 int max, | 54 int max, |
52 int bucket_count); | 55 int bucket_count); |
53 // @} | 56 // @} |
54 | 57 |
| 58 protected: |
| 59 // Starts ceee broker process. This is unittest seam. |
| 60 virtual HRESULT StartServer(IUnknown** server); |
| 61 |
55 private: | 62 private: |
56 void LockContext(); | 63 void LockContext(); |
57 void ReleaseContext(); | 64 void ReleaseContext(); |
58 | 65 |
| 66 template<class Function, class Params> |
| 67 HRESULT RunRpc(bool allow_restart, |
| 68 Function rpc_function, |
| 69 const Params& params); |
| 70 |
59 RPC_BINDING_HANDLE binding_handle_; | 71 RPC_BINDING_HANDLE binding_handle_; |
60 // Context handle. It is required to make RPC server know number of active | 72 // Context handle. It is required to make RPC server know number of active |
61 // clients. | 73 // clients. |
62 void* context_; | 74 void* context_; |
| 75 bool allow_restarts_; |
63 DISALLOW_COPY_AND_ASSIGN(BrokerRpcClient); | 76 DISALLOW_COPY_AND_ASSIGN(BrokerRpcClient); |
64 }; | 77 }; |
65 | 78 |
66 #endif // CEEE_IE_BROKER_BROKER_RPC_CLIENT_H_ | 79 #endif // CEEE_IE_BROKER_BROKER_RPC_CLIENT_H_ |
OLD | NEW |