libzypp 17.31.23
PluginFrame.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#ifndef ZYPP_PLUGINFRAME_H
13#define ZYPP_PLUGINFRAME_H
14
15#include <iosfwd>
16#include <string>
17#include <map>
18
19#include <zypp/base/PtrTypes.h>
20
22
24namespace zypp
25{
26
41 {
42 friend std::ostream & operator<<( std::ostream & str, const PluginFrame & obj );
43 friend bool operator==( const PluginFrame & lhs, const PluginFrame & rhs );
44
45 typedef const std::initializer_list<std::pair<std::string,std::string>> & HeaderInitializerList;
46
47 public:
49 static const std::string & ackCommand();
51 static const std::string & errorCommand();
53 static const std::string & enomethodCommand();
54
55 public:
58
61
65 PluginFrame( const std::string & command_r );
66
70 PluginFrame( const std::string & command_r, const std::string & body_r );
71
75 PluginFrame( const std::string & command_r, HeaderInitializerList contents_r );
76
80 PluginFrame( const std::string & command_r, const std::string & body_r, HeaderInitializerList contents_r );
81
86 PluginFrame( std::istream & stream_r );
87
88 public:
90 bool empty() const;
91
93 explicit operator bool() const
94 { return !empty(); }
95
96 public:
98 const std::string & command() const;
99
103 void setCommand( const std::string & command_r );
104
106 bool isAckCommand() const
107 { return command() == ackCommand(); }
108
110 bool isErrorCommand() const
111 {return command() == errorCommand(); }
112
115 {return command() == enomethodCommand(); }
116
118 const std::string & body() const;
119
128 std::string & bodyRef();
129
131 void setBody( const std::string & body_r );
132
133 public:
135 typedef std::multimap<std::string, std::string> HeaderList;
136
138 typedef HeaderList::const_iterator HeaderListIterator;
139
140 private:
143
144 public:
146 const HeaderList & headerList() const;
147
149 bool headerEmpty() const
150 { return headerList().empty(); }
151
153 unsigned headerSize() const
154 { return headerList().size(); }
155
158 { return headerList().begin(); }
159
162 { return headerList().end(); }
163
166 { headerList().clear(); }
167
168
170 bool hasKey( const std::string & key_r ) const
171 { return ! keyEmpty( key_r ); }
172
174 bool keyEmpty( const std::string & key_r ) const
175 { return headerList().find( key_r ) == headerEnd(); }
176
178 bool keySize( const std::string & key_r ) const
179 { return headerList().count( key_r ); }
180
182 HeaderListIterator keyBegin( const std::string & key_r ) const
183 { return headerList().lower_bound( key_r ); }
184
186 HeaderListIterator keyEnd( const std::string & key_r ) const
187 { return headerList().upper_bound( key_r ); }
188
189
194 const std::string & getHeader( const std::string & key_r ) const;
195
199 const std::string & getHeader( const std::string & key_r, const std::string & default_r ) const;
200
202 const std::string & getHeaderNT( const std::string & key_r, const std::string & default_r = std::string() ) const;
203
208 void setHeader( const std::string & key_r, const std::string & value_r = std::string() );
209
215 { headerList().clear(); addHeader( contents_r ); }
216
221 void addHeader( const std::string & key_r, const std::string & value_r = std::string() );
223 void addHeader( HeaderInitializerList contents_r );
224
226 void clearHeader( const std::string & key_r );
227
228 public:
232 std::ostream & writeTo( std::ostream & stream_r ) const;
233
235 static std::ostream & writeTo( std::ostream & stream_r, const PluginFrame & frame_r )
236 { return frame_r.writeTo( stream_r ); }
237
241 std::istream & readFrom( std::istream & stream_r )
242 { *this = PluginFrame( stream_r ); return stream_r; }
243
245 static std::istream & readFrom( std::istream & stream_r, PluginFrame & frame_r )
246 { frame_r = PluginFrame( stream_r ); return stream_r; }
247
248 public:
250 struct Impl;
251 private:
254 };
255
257 std::ostream & operator<<( std::ostream & str, const PluginFrame & obj );
258
260 inline std::ostream & dumpOn( std::ostream & str, const PluginFrame & obj )
261 { if ( str ) try { PluginFrame::writeTo( str, obj ); } catch(...){}; return str; }
262
264 inline std::istream & operator>>( std::istream & str, PluginFrame & obj )
265 { return PluginFrame::readFrom( str, obj ); }
266
268 bool operator==( const PluginFrame & lhs, const PluginFrame & rhs );
269
271 inline bool operator!=( const PluginFrame & lhs, const PluginFrame & rhs )
272 { return( ! operator==( lhs, rhs ) ); }
273
275} // namespace zypp
277#endif // ZYPP_PLUGINFRAME_H
RepoManager implementation.
Base class for PluginFrame Exception.
Command frame for communication with PluginScript.
Definition: PluginFrame.h:41
const std::initializer_list< std::pair< std::string, std::string > > & HeaderInitializerList
Definition: PluginFrame.h:45
static const std::string & ackCommand()
"ACK" command.
Definition: PluginFrame.cc:241
void setCommand(const std::string &command_r)
Set the frame command.
Definition: PluginFrame.cc:289
friend bool operator==(const PluginFrame &lhs, const PluginFrame &rhs)
Definition: PluginFrame.cc:336
void setBody(const std::string &body_r)
Set the frame body.
Definition: PluginFrame.cc:298
const std::string & body() const
Return the frame body.
Definition: PluginFrame.cc:292
HeaderListIterator keyBegin(const std::string &key_r) const
Return iterator pointing to the 1st header for key_r (or keyEnd(key_r))
Definition: PluginFrame.h:182
PluginFrame()
Default ctor (empty frame)
Definition: PluginFrame.cc:259
void headerClear()
Clear the list of headers.
Definition: PluginFrame.h:165
std::string & bodyRef()
Return a reference to the frame body.
Definition: PluginFrame.cc:295
void setHeader(HeaderInitializerList contents_r)
Set a new header list.
Definition: PluginFrame.h:214
bool headerEmpty() const
Whether header list is empty.
Definition: PluginFrame.h:149
void clearHeader(const std::string &key_r)
Remove all headers for key_r.
Definition: PluginFrame.cc:328
HeaderList::const_iterator HeaderListIterator
Header list iterator.
Definition: PluginFrame.h:138
bool keyEmpty(const std::string &key_r) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: PluginFrame.h:174
unsigned headerSize() const
Return size of the header list.
Definition: PluginFrame.h:153
bool isErrorCommand() const
Convenience to identify an ERROR command.
Definition: PluginFrame.h:110
std::istream & readFrom(std::istream &stream_r)
Read frame from stream.
Definition: PluginFrame.h:241
bool empty() const
Whether this is an empty frame.
Definition: PluginFrame.cc:283
static const std::string & enomethodCommand()
"_ENOMETHOD" command.
Definition: PluginFrame.cc:253
bool keySize(const std::string &key_r) const
Return number of header entries for key_r.
Definition: PluginFrame.h:178
std::ostream & dumpOn(std::ostream &str, const PluginFrame &obj)
Stream output writing all data for logging (no throw)
Definition: PluginFrame.h:260
friend std::ostream & operator<<(std::ostream &str, const PluginFrame &obj)
Definition: PluginFrame.cc:333
const std::string & command() const
Return the frame command.
Definition: PluginFrame.cc:286
void addHeader(const std::string &key_r, const std::string &value_r=std::string())
Add header for key_r leaving already existing headers for key_r unchanged.
Definition: PluginFrame.cc:322
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: PluginFrame.h:253
bool isEnomethodCommand() const
Convenience to identify an _ENOMETHOD command.
Definition: PluginFrame.h:114
HeaderListIterator keyEnd(const std::string &key_r) const
Return iterator pointing behind the last header for key_r.
Definition: PluginFrame.h:186
static const std::string & errorCommand()
"ERROR" command.
Definition: PluginFrame.cc:247
std::multimap< std::string, std::string > HeaderList
The header list.
Definition: PluginFrame.h:135
bool operator!=(const PluginFrame &lhs, const PluginFrame &rhs)
Comparison based on content.
Definition: PluginFrame.h:271
static std::istream & readFrom(std::istream &stream_r, PluginFrame &frame_r)
Definition: PluginFrame.h:245
static std::ostream & writeTo(std::ostream &stream_r, const PluginFrame &frame_r)
Definition: PluginFrame.h:235
HeaderListIterator headerEnd() const
Return iterator pointing behind the last header.
Definition: PluginFrame.h:161
const std::string & getHeader(const std::string &key_r) const
Return header value for key_r.
Definition: PluginFrame.cc:310
std::istream & operator>>(std::istream &str, PluginFrame &obj)
Construct from stream.
Definition: PluginFrame.h:264
HeaderList & headerList()
Modifyalble header list for internal use only.
Definition: PluginFrame.cc:304
void setHeader(const std::string &key_r, const std::string &value_r=std::string())
Set header for key_r removing all other occurrences of key_r.
Definition: PluginFrame.cc:319
const std::string & getHeaderNT(const std::string &key_r, const std::string &default_r=std::string()) const
Not throwing version returing one of the matching header values or default_r string.
Definition: PluginFrame.cc:316
bool isAckCommand() const
Convenience to identify an ACK command.
Definition: PluginFrame.h:106
HeaderListIterator headerBegin() const
Return iterator pointing to the 1st header (or headerEnd)
Definition: PluginFrame.h:157
PluginFrameException Exception
Default exception type.
Definition: PluginFrame.h:57
std::ostream & writeTo(std::ostream &stream_r) const
Write frame to stream.
Definition: PluginFrame.cc:301
bool hasKey(const std::string &key_r) const
Whether the header list contains at least one entry for key_r.
Definition: PluginFrame.h:170
String related utilities and Regular expression matching.
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
bool operator==(const SetRelation::Enum &lhs, const SetCompare &rhs)
This is an overloaded member function, provided for convenience. It differs from the above function o...
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
Definition: SerialNumber.cc:52
RW_pointer supporting 'copy on write' functionality.
Definition: PtrTypes.h:459