blob: 1a4400596f0664e30ed9aa70bea34d6fbed3dd3c [file] [log] [blame]
Qiuhan Ding0cfc1512015-02-17 17:44:11 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
Varun Patila24bd3e2020-11-24 10:08:33 +05303 * Copyright (c) 2020, Regents of the University of California
Qiuhan Ding0cfc1512015-02-17 17:44:11 -08004 *
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
Varun Patila24bd3e2020-11-24 10:08:33 +053064 ChatMessageType
Qiuhan Ding0cfc1512015-02-17 17:44:11 -080065 getMsgType() const;
66
67 const std::string&
68 getData() const;
69
Varun Patila24bd3e2020-11-24 10:08:33 +053070 time_t
Qiuhan Ding0cfc1512015-02-17 17:44:11 -080071 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:
Varun Patil3d850902020-11-23 12:19:14 +053089 template<ndn::encoding::Tag T>
Qiuhan Ding0cfc1512015-02-17 17:44:11 -080090 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
Varun Patila24bd3e2020-11-24 10:08:33 +0530115inline ChatMessage::ChatMessageType
Qiuhan Ding0cfc1512015-02-17 17:44:11 -0800116ChatMessage::getMsgType() const
117{
118 return m_msgType;
119}
120
121inline const std::string&
122ChatMessage::getData() const
123{
124 return m_data;
125}
126
Varun Patila24bd3e2020-11-24 10:08:33 +0530127inline time_t
Qiuhan Ding0cfc1512015-02-17 17:44:11 -0800128ChatMessage::getTimestamp() const
129{
130 return m_timestamp;
131}
132
133} // namespace chronochat
134
Varun Patila24bd3e2020-11-24 10:08:33 +0530135#endif // CHRONOCHAT_CHAT_MESSAGE_HPP