File: RLogNode.h

package info (click to toggle)
rlog 1.4-2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 2,644 kB
  • sloc: sh: 9,196; cpp: 1,601; makefile: 129
file content (103 lines) | stat: -rw-r--r-- 3,026 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*****************************************************************************
 * Author:   Valient Gough <vgough@pobox.com>
 *
 *****************************************************************************
 * Copyright (c) 2003, Valient Gough
 *
 * This library is free software; you can distribute it and/or modify it under
 * the terms of the GNU Lesser General Public License (LGPL), as published by
 * the Free Software Foundation; either version 2.1 of the License, or (at your
 * option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the LGPL in the file COPYING for more
 * details.
 *
 */
		                                                                                

#ifndef _RLogNode_incl_
#define _RLogNode_incl_

#include <list>
#include <set>
#include <time.h>
#include <string>

#include <rlog/common.h>
#include <rlog/Mutex.h>

namespace rlog
{
    class RLOG_DECL RLogNode;

    /*! @struct RLogData <rlog/RLogNode.h>
      @brief Data published through RLogNode

      RLogData is the data which is published from rDebug(), rWarning(),
      rError() and rLog() macros.  It contains a link to the publisher, the
      (approximate) time of the publication, and the formatted message.

      Note that none of the data in the publication is considered to be static.
      Once control has returned to the publisher, the data may be destroyed. If
      it is necessary to hang on to any of the data, a deep copy must be made.

    */
    struct RLOG_DECL RLogData
    {
	struct PublishLoc *publisher;
	//! time of publication
	time_t time;
	//! formatted msg - gets destroyed when publish() call returns.
	const char *msg; 

	// track which nodes have seen this message, to avoid getting
	// duplicates.  It would be nice if we could enforce this via the node
	// structure instead, but that is much harder.
	std::set< RLogNode * > seen;
    };

    // documentation in implementation file
    class RLogNode
    {
    public:
	RLogNode();
	virtual ~RLogNode();

	// remove this node from the subscription network
	virtual void clear();

	virtual void publish( const RLogData &data );

	// primary interface
	virtual void addPublisher( RLogNode * );
	virtual void dropPublisher( RLogNode *, bool callbacks=true );

	bool enabled() const;

	// used internally - see documentation
	virtual void addSubscriber( RLogNode * );
	virtual void dropSubscriber( RLogNode * );

	virtual void isInterested( RLogNode *node, bool isInterested );

    protected:
	// called by RLogNode when enable state changed.
	virtual void setEnabled(bool newState);

	//! list of nodes we are subscribed to
	std::list< RLogNode * > publishers;

	//! list of nodes we publish to
	std::list< RLogNode * > subscribers;

	//! list of subscribers that are interested in receiving publications..
	std::list< RLogNode * > interestList;

	Mutex mutex;
    };
}

#endif