author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Mon, 10 Mar 2008 14:57:04 -0700 | |
changeset 2587 | d8bf55c18428 |
parent 2569 | d5cff2968984 |
child 2594 | a8f89acd17a1 |
permissions | -rw-r--r-- |
2587 | 1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 |
/* |
|
3 |
* Copyright (c) 2008 INRIA |
|
4 |
* |
|
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; |
|
8 |
* |
|
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. |
|
13 |
* |
|
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 |
|
17 |
* |
|
18 |
* Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
|
19 |
*/ |
|
2463
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
20 |
#ifndef TRACE_SOURCE_ACCESSOR_H |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
21 |
#define TRACE_SOURCE_ACCESSOR_H |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
22 |
|
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
23 |
#include <stdint.h> |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
24 |
#include "object-base.h" |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
25 |
#include "callback.h" |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
26 |
#include "ptr.h" |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
27 |
|
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
28 |
namespace ns3 { |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
29 |
|
2587 | 30 |
/** |
31 |
* \brief control access to objects' trace sources |
|
32 |
* |
|
33 |
* This class abstracts the kind of trace source to which we want to connect. |
|
34 |
*/ |
|
2463
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
35 |
class TraceSourceAccessor : public ObjectBase |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
36 |
{ |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
37 |
public: |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
38 |
TraceSourceAccessor (); |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
39 |
virtual ~TraceSourceAccessor (); |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
40 |
void Ref (void) const; |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
41 |
void Unref (void) const; |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
42 |
|
2587 | 43 |
/** |
44 |
* \param obj the object instance which contains the target trace source. |
|
45 |
* \param cb the callback to connect to the target trace source. |
|
46 |
*/ |
|
2463
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
47 |
virtual bool Connect (ObjectBase *obj, const CallbackBase &cb) const = 0; |
2587 | 48 |
/** |
49 |
* \param obj the object instance which contains the target trace source. |
|
50 |
* \param context the context to bind to the user callback. |
|
51 |
* \param cb the callback to connect to the target trace source. |
|
52 |
*/ |
|
2531
b451b5fc8b57
implement context-based trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2463
diff
changeset
|
53 |
virtual bool ConnectWithContext (ObjectBase *obj, std::string context, const CallbackBase &cb) const = 0; |
2587 | 54 |
/** |
55 |
* \param obj the object instance which contains the target trace source. |
|
56 |
* \param cb the callback to disconnect from the target trace source. |
|
57 |
*/ |
|
2463
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
58 |
virtual bool Disconnect (ObjectBase *obj, const CallbackBase &cb) const = 0; |
2587 | 59 |
/** |
60 |
* \param obj the object instance which contains the target trace source. |
|
61 |
* \param context the context which was bound to the user callback. |
|
62 |
* \param cb the callback to disconnect from the target trace source. |
|
63 |
*/ |
|
2569
d5cff2968984
make Disconnect work with trace contexts.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2531
diff
changeset
|
64 |
virtual bool DisconnectWithContext (ObjectBase *obj, std::string context, const CallbackBase &cb) const = 0; |
2463
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
65 |
private: |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
66 |
mutable uint32_t m_count; |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
67 |
}; |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
68 |
|
2587 | 69 |
/** |
70 |
* \param a the trace source |
|
71 |
* |
|
72 |
* Create a TraceSourceAccessor which will control access to the underlying |
|
73 |
* trace source. |
|
74 |
*/ |
|
2463
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
75 |
template <typename T> |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
76 |
Ptr<const TraceSourceAccessor> MakeTraceSourceAccessor (T a); |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
77 |
|
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
78 |
} // namespace ns3 |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
79 |
|
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
80 |
namespace ns3 { |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
81 |
|
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
82 |
template <typename T, typename SOURCE> |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
83 |
Ptr<const TraceSourceAccessor> |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
84 |
DoMakeTraceSourceAccessor (SOURCE T::*a) |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
85 |
{ |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
86 |
struct Accessor : public TraceSourceAccessor |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
87 |
{ |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
88 |
virtual bool Connect (ObjectBase *obj, const CallbackBase &cb) const { |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
89 |
T *p = dynamic_cast<T*> (obj); |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
90 |
if (p == 0) |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
91 |
{ |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
92 |
return false; |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
93 |
} |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
94 |
(p->*m_source).Connect (cb); |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
95 |
return true; |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
96 |
} |
2531
b451b5fc8b57
implement context-based trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2463
diff
changeset
|
97 |
virtual bool ConnectWithContext (ObjectBase *obj, std::string context, const CallbackBase &cb) const { |
b451b5fc8b57
implement context-based trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2463
diff
changeset
|
98 |
T *p = dynamic_cast<T*> (obj); |
b451b5fc8b57
implement context-based trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2463
diff
changeset
|
99 |
if (p == 0) |
b451b5fc8b57
implement context-based trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2463
diff
changeset
|
100 |
{ |
b451b5fc8b57
implement context-based trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2463
diff
changeset
|
101 |
return false; |
b451b5fc8b57
implement context-based trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2463
diff
changeset
|
102 |
} |
b451b5fc8b57
implement context-based trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2463
diff
changeset
|
103 |
(p->*m_source).ConnectWithContext (cb, context); |
b451b5fc8b57
implement context-based trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2463
diff
changeset
|
104 |
return true; |
b451b5fc8b57
implement context-based trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2463
diff
changeset
|
105 |
} |
2463
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
106 |
virtual bool Disconnect (ObjectBase *obj, const CallbackBase &cb) const { |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
107 |
T *p = dynamic_cast<T*> (obj); |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
108 |
if (p == 0) |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
109 |
{ |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
110 |
return false; |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
111 |
} |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
112 |
(p->*m_source).Disconnect (cb); |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
113 |
return true; |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
114 |
} |
2569
d5cff2968984
make Disconnect work with trace contexts.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2531
diff
changeset
|
115 |
virtual bool DisconnectWithContext (ObjectBase *obj, std::string context, const CallbackBase &cb) const { |
d5cff2968984
make Disconnect work with trace contexts.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2531
diff
changeset
|
116 |
T *p = dynamic_cast<T*> (obj); |
d5cff2968984
make Disconnect work with trace contexts.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2531
diff
changeset
|
117 |
if (p == 0) |
d5cff2968984
make Disconnect work with trace contexts.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2531
diff
changeset
|
118 |
{ |
d5cff2968984
make Disconnect work with trace contexts.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2531
diff
changeset
|
119 |
return false; |
d5cff2968984
make Disconnect work with trace contexts.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2531
diff
changeset
|
120 |
} |
d5cff2968984
make Disconnect work with trace contexts.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2531
diff
changeset
|
121 |
(p->*m_source).DisconnectWithContext (cb, context); |
d5cff2968984
make Disconnect work with trace contexts.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2531
diff
changeset
|
122 |
return true; |
d5cff2968984
make Disconnect work with trace contexts.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2531
diff
changeset
|
123 |
} |
2463
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
124 |
SOURCE T::*m_source; |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
125 |
} *accessor = new Accessor (); |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
126 |
accessor->m_source = a; |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
127 |
return Ptr<const TraceSourceAccessor> (accessor, false); |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
128 |
} |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
129 |
|
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
130 |
template <typename T> |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
131 |
Ptr<const TraceSourceAccessor> MakeTraceSourceAccessor (T a) |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
132 |
{ |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
133 |
return DoMakeTraceSourceAccessor (a); |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
134 |
} |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
135 |
|
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
136 |
} // namespace ns3 |
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
137 |
|
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
138 |
|
c77e43117673
actually allow connection and disconnection to trace sources registered in TypeIds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
139 |
#endif /* TRACE_SOURCE_ACCESSOR_H */ |