source: trash/old-modules/transport/protlib/messages.h@ 5887

Last change on this file since 5887 was 5641, checked in by Christoph Mayer, 15 years ago
File size: 5.6 KB
RevLine 
[5641]1/// ----------------------------------------*- mode: C++; -*--
2/// @file messages.h
3/// internal messages sent between modules and other components
4/// ----------------------------------------------------------
5/// $Id: messages.h 3013 2008-05-15 16:12:27Z roehricht $
6/// $HeadURL: https://svn.ipv6.tm.uka.de/nsis/protlib/trunk/include/messages.h $
7// ===========================================================
8//
9// Copyright (C) 2005-2007, all rights reserved by
10// - Institute of Telematics, Universitaet Karlsruhe (TH)
11//
12// More information and contact:
13// https://projekte.tm.uka.de/trac/NSIS
14//
15// This program is free software; you can redistribute it and/or modify
16// it under the terms of the GNU General Public License as published by
17// the Free Software Foundation; version 2 of the License
18//
19// This program is distributed in the hope that it will be useful,
20// but WITHOUT ANY WARRANTY; without even the implied warranty of
21// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22// GNU General Public License for more details.
23//
24// You should have received a copy of the GNU General Public License along
25// with this program; if not, write to the Free Software Foundation, Inc.,
26// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27//
28// ===========================================================
29
30/** @ingroup messages
31 * @file
32 * These messages are sent between modules and other DRM components.
33 */
34
35#ifndef _PROTLIB__MESSAGE_H_
36#define _PROTLIB__MESSAGE_H_
37
38#include <pthread.h>
39#include <ext/hash_set>
40
41#include "protlib_types.h"
42#include "fqueue.h"
43
44namespace protlib {
45
46/** @addtogroup messages Internal Messages
47 * @{
48 */
49
50// class FastQueue is declared in fqueue.h
51class FastQueue;
52
53// class Context is declared in context.h
54class Context;
55
56/// internal messages
57/** Base class of all internal drm messages passed between modules. */
58class message {
59public:
60 /// message type
61 /** Each subclass of class message has its own unique type. */
62 enum type_t {
63 type_transport,
64 type_timer,
65 type_signaling,
66 type_context,
67 type_info,
68 type_routing,
69 type_API
70 }; // end type_t
71
72 /// source ID
73 /** Identifies the module which sent the message.
74 * If you add an id here, please add also the corresponding string in qaddr_string
75 */
76 enum qaddr_t {
77 qaddr_unknown, // used as return value in NSLPtable.get_address() if there is no address found
78 qaddr_transport,
79 qaddr_timer,
80 qaddr_coordination,
81 qaddr_coordination_internal,
82 qaddr_signaling,
83 qaddr_policy,
84 qaddr_resource,
85 qaddr_routing,
86 qaddr_accounting,
87 qaddr_router_config,
88 qaddr_tp_over_sctp,
89 qaddr_tp_over_tcp,
90 qaddr_tp_over_tls_tcp,
91 qaddr_tp_over_udp,
92 qaddr_tp_queryencap,
93 qaddr_qos_nslp_timerprocessing,
94 qaddr_qos_nslp_coordination,
95 qaddr_qos_nslp_signaling,
96 qaddr_appl_qos_signaling,
97 qaddr_qos_appl_signaling,
98 qaddr_gui,
99 qaddr_api_0,
100 qaddr_api_1,
101 qaddr_api_2,
102 qaddr_api_3,
103 qaddr_api_4,
104 qaddr_api_5,
105 qaddr_api_6,
106 qaddr_api_7,
107 qaddr_api_wrapper_input,
108 qaddr_tp_over_uds,
109 qaddr_uds_appl_qos // receives messages from an external client via UDS
110 }; // end qaddr_t
111
112 /// message ID
113 /** Each message has an ID.
114 * Message IDs are not unique, you can use the same ID e.g. for request
115 * and response. You cannot use an unused message ID, you can just reuse
116 * an already used ID. ID 0 sets an unused ID.
117 * Since id_t is 64-bit long, you can send 10^10 messages per seconds
118 * for over 30 years without reusing an ID.
119 */
120 typedef gp_id_t id_t;
121 /// constructor
122 message(type_t t, qaddr_t s = qaddr_unknown, id_t id = 0);
123 /// destructor
124 virtual ~message();
125 /// get ID
126 id_t get_id() const;
127 /// set ID or generate a new one
128 id_t set_id(id_t id);
129 /// get new ID
130 id_t new_id();
131 /// get message type
132 type_t get_type() const;
133 /// get source module queue
134 FastQueue *get_source_queue() const;
135 /// get source ID
136 qaddr_t get_source() const;
137 /// set source ID
138 qaddr_t set_source(qaddr_t s);
139 /// get name of message source
140 const char* get_qaddr_name() const;
141 /// get source name
142 static const char* get_qaddr_name(qaddr_t s);
143 /// get name of message type
144 const char* get_type_name() const { return type_string[type]; }
145 /// get type name
146 static const char* get_type_name(type_t t) { return type_string[t]; }
147 /// send the message to a queue
148 bool send(qaddr_t src, FastQueue* destqueue, bool exp = false);
149 /// send the message
150 bool send(qaddr_t src, qaddr_t dest, bool exp = false);
151 // @{
152 /// send the message to dest
153 bool send_to(qaddr_t dest, bool exp = false);
154 bool send_to(FastQueue* destqueue, bool exp = false);
155 // @}
156 /// send the message back
157 bool send_back(qaddr_t from, bool exp = false);
158 //@{
159 /// send or delete the message
160 void send_or_delete(qaddr_t src, qaddr_t dest, bool exp = false) { if (!send(src,dest,exp)) delete this; }
161 void send_to_or_delete(qaddr_t dest, bool exp = false) { if (!send_to(dest,exp)) delete this; }
162 void send_back_or_delete(qaddr_t src, bool exp = false) { if (!send_back(src,exp)) delete this; }
163 //@}
164 /// clear all pointers
165 virtual void clear_pointers();
166private:
167 const type_t type;
168 qaddr_t source;
169 id_t msg_id;
170 /// printable message source names
171 static const char* const qaddr_string[];
172 /// printable message typee names
173 static const char* const type_string[];
174}; // end class message
175
176
177
178//@}
179
180} // end namespace protlib
181
182namespace __gnu_cxx {
183
184/// message pointer hasher
185/** Hash value is the address of the object pointed to. */
186template <> struct hash<protlib::message*> {
187 inline size_t operator()(protlib::message* m) const { return (size_t)m; }
188}; // end msgp_hash
189
190} // end namespace __gnu_cxx
191
192#endif // _PROTLIB__MESSAGE_H_
Note: See TracBrowser for help on using the repository browser.