Open Lighting Architecture  0.9.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RDMReply.h
1 /*
2  * This library is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU Lesser General Public
4  * License as published by the Free Software Foundation; either
5  * version 2.1 of the License, or (at your option) any later version.
6  *
7  * This library is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10  * Lesser General Public License for more details.
11  *
12  * You should have received a copy of the GNU Lesser General Public
13  * License along with this library; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15  *
16  * RDMReply.h
17  * The RDMReply object.
18  * Copyright (C) 2015 Simon Newton
19  */
20 
21 #ifndef INCLUDE_OLA_RDM_RDMREPLY_H_
22 #define INCLUDE_OLA_RDM_RDMREPLY_H_
23 
24 #include <ola/base/Macro.h>
25 #include <ola/rdm/RDMCommand.h>
26 #include <ola/rdm/RDMFrame.h>
27 #include <ola/rdm/RDMResponseCodes.h>
28 
29 #include <string>
30 #include <memory>
31 
32 namespace ola {
33 namespace rdm {
34 
43 struct RDMReply {
44  public:
48  explicit RDMReply(RDMStatusCode status_code);
49 
55  RDMReply(RDMStatusCode status_code, RDMResponse *response);
56 
63  RDMReply(RDMStatusCode status_code,
64  RDMResponse *response,
65  const RDMFrames &frames);
66 
70  RDMStatusCode StatusCode() const { return m_status_code; }
71 
79  const RDMResponse* Response() const { return m_response.get(); }
80 
88  RDMResponse* MutableResponse() { return m_response.get(); }
89 
95  const RDMFrames& Frames() const { return m_frames; }
96 
102  bool operator==(const RDMReply &other) const;
103 
113  std::string ToString() const;
114 
121  friend std::ostream& operator<<(std::ostream &out,
122  const RDMReply &reply) {
123  return out << reply.ToString();
124  }
125 
134  static RDMReply* FromFrame(const RDMFrame &frame,
135  const RDMRequest *request = NULL);
136 
143  static RDMReply* DUBReply(const RDMFrame &frame);
144 
145  private:
146  RDMStatusCode m_status_code;
147  std::auto_ptr<RDMResponse> m_response;
148  RDMFrames m_frames;
149 
150  DISALLOW_COPY_AND_ASSIGN(RDMReply);
151 };
152 } // namespace rdm
153 } // namespace ola
154 #endif // INCLUDE_OLA_RDM_RDMREPLY_H_