1 : // Copyright 2012 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 : //
15 : // This file declares the RpcLoggerInstanceManager which binds the call
16 : // trace service RPC handlers to a trace::agent_logger::Logger instance.
17 :
18 : #ifndef SYZYGY_TRACE_AGENT_LOGGER_AGENT_LOGGER_RPC_IMPL_H_
19 : #define SYZYGY_TRACE_AGENT_LOGGER_AGENT_LOGGER_RPC_IMPL_H_
20 :
21 : #include "base/logging.h"
22 :
23 : namespace trace {
24 : namespace agent_logger {
25 :
26 : // Forward declaration.
27 : class AgentLogger;
28 :
29 : // A helper class to manage a "global" Logger instance to which the RPC
30 : // callbacks are bound. You can create an instance of this manager to
31 : // bind and unbind a given instance to the callbacks within a particular
32 : // scope.
33 : class RpcLoggerInstanceManager {
34 : public:
35 E : explicit RpcLoggerInstanceManager(AgentLogger* logger) {
36 E : DCHECK(logger != NULL);
37 E : DCHECK(instance_ == NULL);
38 E : instance_ = logger;
39 E : }
40 :
41 E : ~RpcLoggerInstanceManager() {
42 E : DCHECK(instance_ != NULL);
43 E : instance_ = NULL;
44 E : }
45 :
46 E : static AgentLogger* GetInstance() {
47 E : DCHECK(instance_ != NULL);
48 E : return instance_;
49 E : }
50 :
51 : protected:
52 : static AgentLogger* instance_;
53 : };
54 :
55 : } // namespace agent_logger
56 : } // namespace trace
57 :
58 : #endif // SYZYGY_TRACE_AGENT_LOGGER_AGENT_LOGGER_RPC_IMPL_H_
|