replace RefCountBase with SimpleRefCount<> to avoid duplicate refcounting implementations.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
3 * Copyright (c) 2008 INRIA
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
20 #ifndef TRACE_SOURCE_ACCESSOR_H
21 #define TRACE_SOURCE_ACCESSOR_H
26 #include "simple-ref-count.h"
35 * \brief control access to objects' trace sources
37 * This class abstracts the kind of trace source to which we want to connect
38 * and provides services to Connect and Disconnect a sink to a trace source.
40 class TraceSourceAccessor : public SimpleRefCount<TraceSourceAccessor>
43 TraceSourceAccessor ();
44 virtual ~TraceSourceAccessor ();
47 * \param obj the object instance which contains the target trace source.
48 * \param cb the callback to connect to the target trace source.
50 virtual bool ConnectWithoutContext (ObjectBase *obj, const CallbackBase &cb) const = 0;
52 * \param obj the object instance which contains the target trace source.
53 * \param context the context to bind to the user callback.
54 * \param cb the callback to connect to the target trace source.
56 virtual bool Connect (ObjectBase *obj, std::string context, const CallbackBase &cb) const = 0;
58 * \param obj the object instance which contains the target trace source.
59 * \param cb the callback to disconnect from the target trace source.
61 virtual bool DisconnectWithoutContext (ObjectBase *obj, const CallbackBase &cb) const = 0;
63 * \param obj the object instance which contains the target trace source.
64 * \param context the context which was bound to the user callback.
65 * \param cb the callback to disconnect from the target trace source.
67 virtual bool Disconnect (ObjectBase *obj, std::string context, const CallbackBase &cb) const = 0;
71 * \param a the trace source
73 * Create a TraceSourceAccessor which will control access to the underlying
74 * trace source. This helper template method assumes that the underlying
75 * type implements a statically-polymorphic set of Connect and Disconnect
76 * methods and creates a dynamic-polymorphic class to wrap the underlying
77 * static-polymorphic class.
80 Ptr<const TraceSourceAccessor> MakeTraceSourceAccessor (T a);
86 template <typename T, typename SOURCE>
87 Ptr<const TraceSourceAccessor>
88 DoMakeTraceSourceAccessor (SOURCE T::*a)
90 struct Accessor : public TraceSourceAccessor
92 virtual bool ConnectWithoutContext (ObjectBase *obj, const CallbackBase &cb) const {
93 T *p = dynamic_cast<T*> (obj);
98 (p->*m_source).ConnectWithoutContext (cb);
101 virtual bool Connect (ObjectBase *obj, std::string context, const CallbackBase &cb) const {
102 T *p = dynamic_cast<T*> (obj);
107 (p->*m_source).Connect (cb, context);
110 virtual bool DisconnectWithoutContext (ObjectBase *obj, const CallbackBase &cb) const {
111 T *p = dynamic_cast<T*> (obj);
116 (p->*m_source).DisconnectWithoutContext (cb);
119 virtual bool Disconnect (ObjectBase *obj, std::string context, const CallbackBase &cb) const {
120 T *p = dynamic_cast<T*> (obj);
125 (p->*m_source).Disconnect (cb, context);
129 } *accessor = new Accessor ();
130 accessor->m_source = a;
131 return Ptr<const TraceSourceAccessor> (accessor, false);
134 template <typename T>
135 Ptr<const TraceSourceAccessor> MakeTraceSourceAccessor (T a)
137 return DoMakeTraceSourceAccessor (a);
143 #endif /* TRACE_SOURCE_ACCESSOR_H */