Qiuhan Ding | 0cfc151 | 2015-02-17 17:44:11 -0800 | [diff] [blame] | 1 | /* -*- 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 | |
| 20 | namespace chronochat { |
| 21 | |
| 22 | class ChatMessage |
| 23 | { |
| 24 | |
| 25 | public: |
| 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 | |
| 45 | public: |
| 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 | |
| 88 | private: |
| 89 | template<bool T> |
| 90 | size_t |
Alexander Afanasyev | 28eb909 | 2015-06-29 20:15:11 -0700 | [diff] [blame^] | 91 | wireEncode(ndn::EncodingImpl<T>& encoder) const; |
Qiuhan Ding | 0cfc151 | 2015-02-17 17:44:11 -0800 | [diff] [blame] | 92 | |
| 93 | private: |
| 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 | |
| 103 | inline const std::string& |
| 104 | ChatMessage::getNick() const |
| 105 | { |
| 106 | return m_nick; |
| 107 | } |
| 108 | |
| 109 | inline const std::string& |
| 110 | ChatMessage::getChatroomName() const |
| 111 | { |
| 112 | return m_chatroomName; |
| 113 | } |
| 114 | |
| 115 | inline const ChatMessage::ChatMessageType |
| 116 | ChatMessage::getMsgType() const |
| 117 | { |
| 118 | return m_msgType; |
| 119 | } |
| 120 | |
| 121 | inline const std::string& |
| 122 | ChatMessage::getData() const |
| 123 | { |
| 124 | return m_data; |
| 125 | } |
| 126 | |
| 127 | inline const time_t |
| 128 | ChatMessage::getTimestamp() const |
| 129 | { |
| 130 | return m_timestamp; |
| 131 | } |
| 132 | |
| 133 | } // namespace chronochat |
| 134 | |
| 135 | #endif //CHRONOCHAT_CHAT_MESSAGE_HPP |