libzypp 17.32.2
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 using HeaderInitializerList = const std::initializer_list<std::pair<std::string, std::string>> &;
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, std::string body_r );
71
76
80 PluginFrame(const std::string & command_r, 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 using HeaderList = std::multimap<std::string, std::string>;
136
138 using HeaderListIterator = HeaderList::const_iterator;
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
216
221 void addHeader( const std::string & key_r, const std::string & value_r = std::string() );
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.
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
Definition AutoDispose.h:95
Base class for PluginFrame Exception.
Command frame for communication with PluginScript.
Definition PluginFrame.h:41
static const std::string & ackCommand()
"ACK" command.
void setCommand(const std::string &command_r)
Set the frame command.
HeaderList::const_iterator HeaderListIterator
Header list iterator.
friend bool operator==(const PluginFrame &lhs, const PluginFrame &rhs)
void setBody(const std::string &body_r)
Set the frame body.
const std::string & body() const
Return the frame body.
const std::initializer_list< std::pair< std::string, std::string > > & HeaderInitializerList
Definition PluginFrame.h:45
HeaderListIterator keyBegin(const std::string &key_r) const
Return iterator pointing to the 1st header for key_r (or keyEnd(key_r))
PluginFrame()
Default ctor (empty frame)
void headerClear()
Clear the list of headers.
std::string & bodyRef()
Return a reference to the frame body.
void setHeader(HeaderInitializerList contents_r)
Set a new header list.
bool headerEmpty() const
Whether header list is empty.
void clearHeader(const std::string &key_r)
Remove all headers for key_r.
bool keyEmpty(const std::string &key_r) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
unsigned headerSize() const
Return size of the header list.
bool isErrorCommand() const
Convenience to identify an ERROR command.
std::istream & readFrom(std::istream &stream_r)
Read frame from stream.
bool empty() const
Whether this is an empty frame.
static const std::string & enomethodCommand()
"_ENOMETHOD" command.
bool keySize(const std::string &key_r) const
Return number of header entries for key_r.
std::ostream & dumpOn(std::ostream &str, const PluginFrame &obj)
Stream output writing all data for logging (no throw)
friend std::ostream & operator<<(std::ostream &str, const PluginFrame &obj)
const std::string & command() const
Return the frame command.
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.
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
bool isEnomethodCommand() const
Convenience to identify an _ENOMETHOD command.
HeaderListIterator keyEnd(const std::string &key_r) const
Return iterator pointing behind the last header for key_r.
static const std::string & errorCommand()
"ERROR" command.
bool operator!=(const PluginFrame &lhs, const PluginFrame &rhs)
Comparison based on content.
static std::istream & readFrom(std::istream &stream_r, PluginFrame &frame_r)
static std::ostream & writeTo(std::ostream &stream_r, const PluginFrame &frame_r)
HeaderListIterator headerEnd() const
Return iterator pointing behind the last header.
const std::string & getHeader(const std::string &key_r) const
Return header value for key_r.
std::multimap< std::string, std::string > HeaderList
The header list.
std::istream & operator>>(std::istream &str, PluginFrame &obj)
Construct from stream.
HeaderList & headerList()
Modifyalble header list for internal use only.
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.
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.
bool isAckCommand() const
Convenience to identify an ACK command.
HeaderListIterator headerBegin() const
Return iterator pointing to the 1st header (or headerEnd)
std::ostream & writeTo(std::ostream &stream_r) const
Write frame to stream.
bool hasKey(const std::string &key_r) const
Whether the header list contains at least one entry for key_r.
String related utilities and Regular expression matching.
Easy-to use interface to the ZYPP dependency resolver.
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)