blob: 860ce9fed37d95cbb8b053c7084fe9129f8e1ae3 [file] [log] [blame]
Qiuhan Ding0cfc1512015-02-17 17:44:11 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2013, Regents of the University of California
4 *
5 * BSD license, See the LICENSE file for more information
6 *
7 * Author: Qiuhan Ding <qiuhanding@cs.ucla.edu>
8 */
9
10#ifndef CHRONOCHAT_CHAT_MESSAGE_HPP
11#define CHRONOCHAT_CHAT_MESSAGE_HPP
12
13#include "common.hpp"
14#include "tlv.hpp"
15#include <ndn-cxx/util/concepts.hpp>
16#include <ndn-cxx/encoding/block.hpp>
17#include <ndn-cxx/encoding/encoding-buffer.hpp>
18#include <boost/concept_check.hpp>
19
20namespace chronochat {
21
22class ChatMessage
23{
24
25public:
26
27 class Error : public std::runtime_error
28 {
29 public:
30 explicit
31 Error(const std::string& what)
32 : std::runtime_error(what)
33 {
34 }
35 };
36
37 enum ChatMessageType {
38 CHAT = 0,
39 HELLO = 1,
40 LEAVE = 2,
41 JOIN = 3,
42 OTHER = 4,
43 };
44
45public:
46
47 ChatMessage();
48
49 explicit
50 ChatMessage(const Block& chatMsgWire);
51
52 const Block&
53 wireEncode() const;
54
55 void
56 wireDecode(const Block& chatMsgWire);
57
58 const std::string&
59 getNick() const;
60
61 const std::string&
62 getChatroomName() const;
63
64 const ChatMessageType
65 getMsgType() const;
66
67 const std::string&
68 getData() const;
69
70 const time_t
71 getTimestamp() const;
72
73 void
74 setNick(const std::string& nick);
75
76 void
77 setChatroomName(const std::string& chatroomName);
78
79 void
80 setMsgType(const ChatMessageType msgType);
81
82 void
83 setData(const std::string& data);
84
85 void
86 setTimestamp(const time_t timestamp);
87
88private:
89 template<bool T>
90 size_t
Alexander Afanasyev28eb9092015-06-29 20:15:11 -070091 wireEncode(ndn::EncodingImpl<T>& encoder) const;
Qiuhan Ding0cfc1512015-02-17 17:44:11 -080092
93private:
94 mutable Block m_wire;
95 std::string m_nick;
96 std::string m_chatroomName;
97 ChatMessageType m_msgType;
98 std::string m_data;
99 time_t m_timestamp;
100
101};
102
103inline const std::string&
104ChatMessage::getNick() const
105{
106 return m_nick;
107}
108
109inline const std::string&
110ChatMessage::getChatroomName() const
111{
112 return m_chatroomName;
113}
114
115inline const ChatMessage::ChatMessageType
116ChatMessage::getMsgType() const
117{
118 return m_msgType;
119}
120
121inline const std::string&
122ChatMessage::getData() const
123{
124 return m_data;
125}
126
127inline const time_t
128ChatMessage::getTimestamp() const
129{
130 return m_timestamp;
131}
132
133} // namespace chronochat
134
135#endif //CHRONOCHAT_CHAT_MESSAGE_HPP