~ubuntu-branches/ubuntu/gutsy/poco/gutsy

« back to all changes in this revision

Viewing changes to Foundation/include/Poco/Message.h

  • Committer: Bazaar Package Importer
  • Author(s): Krzysztof Burghardt
  • Date: 2007-04-27 18:33:48 UTC
  • Revision ID: james.westby@ubuntu.com-20070427183348-xgnpct0qd6a2ip34
Tags: upstream-1.2.9
ImportĀ upstreamĀ versionĀ 1.2.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// Message.h
 
3
//
 
4
// $Id: //poco/1.2/Foundation/include/Poco/Message.h#2 $
 
5
//
 
6
// Library: Foundation
 
7
// Package: Logging
 
8
// Module:  Message
 
9
//
 
10
// Definition of the Message class.
 
11
//
 
12
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
 
13
// and Contributors.
 
14
//
 
15
// Permission is hereby granted, free of charge, to any person or organization
 
16
// obtaining a copy of the software and accompanying documentation covered by
 
17
// this license (the "Software") to use, reproduce, display, distribute,
 
18
// execute, and transmit the Software, and to prepare derivative works of the
 
19
// Software, and to permit third-parties to whom the Software is furnished to
 
20
// do so, all subject to the following:
 
21
// 
 
22
// The copyright notices in the Software and this entire statement, including
 
23
// the above license grant, this restriction and the following disclaimer,
 
24
// must be included in all copies of the Software, in whole or in part, and
 
25
// all derivative works of the Software, unless such copies or derivative
 
26
// works are solely in the form of machine-executable object code generated by
 
27
// a source language processor.
 
28
// 
 
29
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
30
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
31
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
 
32
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
 
33
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
 
34
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 
35
// DEALINGS IN THE SOFTWARE.
 
36
//
 
37
 
 
38
 
 
39
#ifndef Foundation_Message_INCLUDED
 
40
#define Foundation_Message_INCLUDED
 
41
 
 
42
 
 
43
#include "Poco/Foundation.h"
 
44
#include "Poco/Timestamp.h"
 
45
#include <map>
 
46
 
 
47
 
 
48
namespace Poco {
 
49
 
 
50
 
 
51
class Foundation_API Message
 
52
        /// This class represents a log message that is sent through a
 
53
        /// chain of log channels.
 
54
        ///
 
55
        /// A Message contains a priority denoting the severity of the
 
56
        /// message, a source describing its origin, a text describing
 
57
        /// its meaning, the time of its creation, and an identifier of
 
58
        /// the process and thread that created the message.
 
59
        ///
 
60
        /// A Message can also contain any number of named parameters
 
61
        /// that contain additional information about the event that
 
62
        /// caused the message.
 
63
{
 
64
public:
 
65
        enum Priority
 
66
        {
 
67
                PRIO_FATAL = 1,   /// A fatal error. The application will most likely terminate. This is the highest priority.
 
68
                PRIO_CRITICAL,    /// A critical error. The application might not be able to continue running successfully.
 
69
                PRIO_ERROR,       /// An error. An operation did not complete successfully, but the application as a whole is not affected.
 
70
                PRIO_WARNING,     /// A warning. An operation completed with an unexpected result.
 
71
                PRIO_NOTICE,      /// A notice, which is an information with just a higher priority.
 
72
                PRIO_INFORMATION, /// An informational message, usually denoting the successful completion of an operation.
 
73
                PRIO_DEBUG,       /// A debugging message.
 
74
                PRIO_TRACE        /// A tracing message. This is the lowest priority.
 
75
        };
 
76
        
 
77
        Message();
 
78
                /// Creates an empty Message.
 
79
                /// The thread and process ids are set.
 
80
                
 
81
        Message(const std::string& source, const std::string& text, Priority prio);
 
82
                /// Creates a Message with the given source, text and priority.
 
83
                /// The thread and process ids are set.
 
84
                
 
85
        Message(const Message& msg);
 
86
                /// Creates a Message by copying another one.
 
87
                
 
88
        Message(const Message& msg, const std::string& text);
 
89
                /// Creates a Message by copying all but the text from another message.
 
90
                
 
91
        ~Message();
 
92
                /// Destroys the Message.
 
93
        
 
94
        Message& operator = (const Message& msg);
 
95
                /// Assignment operator.
 
96
                
 
97
        void swap(Message& msg);
 
98
                /// Swaps the message with another one. 
 
99
                
 
100
        void setSource(const std::string& src);
 
101
                /// Sets the source of the message.
 
102
                
 
103
        const std::string& getSource() const;
 
104
                /// Returns the source of the message.
 
105
                
 
106
        void setText(const std::string& text);
 
107
                /// Sets the text of the message.
 
108
                
 
109
        const std::string& getText() const;
 
110
                /// Returns the text of the message.
 
111
                
 
112
        void setPriority(Priority prio);
 
113
                /// Sets the priority of the message.
 
114
                
 
115
        Priority getPriority() const;
 
116
                /// Returns the priority of the message.
 
117
        
 
118
        void setTime(const Timestamp& time);
 
119
                /// Sets the time of the message.
 
120
                
 
121
        const Timestamp& getTime() const;
 
122
                /// Returns the time of the message.
 
123
                
 
124
        void setThread(const std::string& thread);
 
125
                /// Sets the thread identifier for the message.
 
126
                
 
127
        const std::string& getThread() const;
 
128
                /// Returns the thread identifier for the message.
 
129
 
 
130
        void setTid(long pid);
 
131
                /// Sets the numeric thread identifier for the message.
 
132
                
 
133
        long getTid() const;
 
134
                /// Returns the numeric thread identifier for the message.
 
135
        
 
136
        void setPid(long pid);
 
137
                /// Sets the process identifier for the message.
 
138
                
 
139
        long getPid() const;
 
140
                /// Returns the process identifier for the message.
 
141
                
 
142
        const std::string& operator [] (const std::string& param) const;
 
143
                /// Returns a const reference to the value of the parameter
 
144
                /// with the given name. Throws a NotFoundException if the
 
145
                /// parameter does not exist.
 
146
                
 
147
        std::string& operator [] (const std::string& param);
 
148
                /// Returns a reference to the value of the parameter with the
 
149
                /// given name. This can be used to set the parameter's value.
 
150
                /// If the parameter does not exist, it is created with an
 
151
                /// empty string value.
 
152
 
 
153
protected:
 
154
        void init();
 
155
        typedef std::map<std::string, std::string> StringMap;
 
156
 
 
157
private:        
 
158
        std::string _source;
 
159
        std::string _text;
 
160
        Priority    _prio;
 
161
        Timestamp   _time;
 
162
        int         _tid;
 
163
        std::string _thread;
 
164
        long        _pid;
 
165
        StringMap*  _pMap;
 
166
};
 
167
 
 
168
 
 
169
//
 
170
// inlines
 
171
//
 
172
inline const std::string& Message::getSource() const
 
173
{
 
174
        return _source;
 
175
}
 
176
 
 
177
 
 
178
inline const std::string& Message::getText() const
 
179
{
 
180
        return _text;
 
181
}
 
182
 
 
183
 
 
184
inline Message::Priority Message::getPriority() const
 
185
{
 
186
        return _prio;
 
187
}
 
188
 
 
189
 
 
190
inline const std::string& Message::getThread() const
 
191
{
 
192
        return _thread;
 
193
}
 
194
 
 
195
 
 
196
inline long Message::getTid() const
 
197
{
 
198
        return _tid;
 
199
}
 
200
 
 
201
 
 
202
inline long Message::getPid() const
 
203
{
 
204
        return _pid;
 
205
}
 
206
 
 
207
 
 
208
inline void swap(Message& m1, Message& m2)
 
209
{
 
210
        m1.swap(m2);
 
211
}
 
212
 
 
213
 
 
214
} // namespace Poco
 
215
 
 
216
 
 
217
#endif // Foundation_Message_INCLUDED