close Warning: Can't use blame annotator:
No changeset 1891 in the repository

source: source/ariba/communication/modules/transport/protlib/messages.cpp@ 4987

Last change on this file since 4987 was 4987, checked in by Christoph Mayer, 15 years ago

isrunning function für timer

File size: 5.6 KB
RevLine 
1/// ----------------------------------------*- mode: C++; -*--
2/// @file messages.cpp
3/// These messages are sent internally between threads (modules)
4/// ----------------------------------------------------------
5/// $Id: messages.cpp 3013 2008-05-15 16:12:27Z roehricht $
6/// $HeadURL: https://svn.ipv6.tm.uka.de/nsis/protlib/trunk/src/messages.cpp $
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/** @ingroup messages
30 * These messages are sent internally between threads (modules).
31 */
32
33#include "messages.h"
34//#include "context.h"
35#include "queuemanager.h"
36#include "cleanuphandler.h"
37#include "threadsafe_db.h"
38
39namespace protlib {
40
41/** @addtogroup messages Internal Messages
42 * @{
43 */
44
45/***** class message *****/
46
47/** This array contains printable names of messages sources. */
48const char* const message::qaddr_string[] = {
49 "UNKNOWN",
50 "TransportProtocol",
51 "TimerModule",
52 "Coordination (ext)", // external
53 "Coordination (int)", // internal
54 "Signaling",
55 "Policy",
56 "ResourceModule",
57 "Routing",
58 "Accounting",
59 "RouterConfiguration",
60 "TPoverSCTP",
61 "TPoverTCP",
62 "TPoverTLS_TCP",
63 "TPoverUDP",
64 "TPoverQueryEncapsulation",
65 "QNSLP-TimerProc",
66 "QNSLP-Coordinator",
67 "QNSLP-Signaling",
68 "APPL-QNSLP-Signaling",
69 "QNSLP-APPL-Signaling",
70 "GUI",
71 "API-0",
72 "API-1",
73 "API-2",
74 "API-3",
75 "API-4",
76 "API-5",
77 "API-6",
78 "API-7",
79 "API Wrapper Input (from TP)",
80 "TPoverUDS",
81 "QoS NSLP Client API over UDS",
82 "(INVALID)"
83}; // end qaddr_string
84
85/** This array contains printable names of message types. */
86const char* const message::type_string[] = {
87 "TPMsg",
88 "TimerMsg",
89 "SignalingMsg",
90 "ContextMsg",
91 "InfoMsg",
92 "RoutingMsg",
93 "APIMsg"
94}; // end type_string
95
96/** Set message type, source ID and source queue.
97 * Set message ID to id if possible, otherwise generate a new ID.
98 */
99message::message(type_t t, qaddr_t s, id_t id)
100: type(t), source(s) {
101 if ((!id) || (!set_id(id))) new_id();
102} // end constructor
103
104/** Destructor does nothing for this class. */
105message::~message() {}
106
107message::id_t message::get_id() const { return msg_id; }
108
109message::id_t message::set_id(id_t id) {
110 if (!id) {
111 new_id();
112 return 0;
113 } else {
114 msg_id = id;
115 return id;
116 } // end if id
117} // end set_id
118
119/** Generate an unused ID. */
120message::id_t message::new_id() {
121 msg_id = 0;
122 while (!msg_id) msg_id = tsdb::get_new_id64();;
123 return msg_id;
124} // end new_id
125
126/** Get the message type. */
127message::type_t message::get_type() const { return type; }
128
129FastQueue* message::get_source_queue() const {
130 return QueueManager::instance()->get_queue(source);
131} // end get_source_queue
132
133message::qaddr_t message::get_source() const {
134 return source;
135} // end get_source
136
137/** Set source ID and return old value. */
138message::qaddr_t message::set_source(qaddr_t s) {
139 register qaddr_t os = source;
140 source = s;
141 return os;
142} // end set_source
143
144/** Returns a pointer to a string containing a printable name of the message
145 * source.
146 */
147const char* message::get_qaddr_name() const {
148 return qaddr_string[source];
149} // end get_source_name
150
151/** Get the name of the given source. */
152const char* message::get_qaddr_name(qaddr_t s) {
153 return qaddr_string[s];
154} // end get_source_name
155
156/** Send this message to destqueue.
157 * @returns false if destqueue is NULL or queue does not accept the message.
158 */
159bool message::send(qaddr_t src, FastQueue* destqueue, bool exp) {
160 if (!destqueue) return false;
161 source = src;
162 return destqueue->enqueue(this,exp);
163} // end send
164
165/** Send this message.
166 * @returns false if destination queue cannot be found or queue does not accept the message.
167 */
168bool message::send(qaddr_t src, qaddr_t dest, bool exp) {
169 FastQueue* destqueue = QueueManager::instance()->get_queue(dest);
170 if (!destqueue) return false;
171 source = src;
172 return destqueue->enqueue(this,exp);
173} // end send
174
175/** Send this message.
176 * @returns false if destination queue cannot be found or queue does not accept the message.
177 */
178bool message::send_to(qaddr_t dest, bool exp) {
179 FastQueue* destqueue = QueueManager::instance()->get_queue(dest);
180 if (destqueue) return destqueue->enqueue(this,exp);
181 else return false;
182} // end send_to
183
184bool message::send_to(FastQueue* destqueue, bool exp) {
185 if (destqueue) return destqueue->enqueue(this,exp);
186 else return false;
187} // end send_to
188
189/** Send back this message.
190 * @returns false if destination queue cannot be found or queue does not accept the message.
191 */
192bool message::send_back(qaddr_t from, bool exp) {
193 FastQueue* destqueue = QueueManager::instance()->get_queue(source);
194 if (!destqueue) return false;
195 source = from;
196 return destqueue->enqueue(this,exp);
197} // end send_back
198
199/** Set all pointer fields to NULL. */
200void message::clear_pointers() {}
201
202
203//@}
204
205} // end namespace protlib
Note: See TracBrowser for help on using the repository browser.