Mengjin Yan | aec7074 | 2014-08-25 10:37:45 -0700 | [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 | * Yingdi Yu |
| 5 | * |
| 6 | * BSD license, See the LICENSE file for more information |
| 7 | * |
| 8 | * Author: Mengjin Yan <jane.yan0129@gmail.com> |
| 9 | * Author: Yingdi Yu <yingdi@cs.ucla.edu> |
Qiuhan Ding | 0cfc151 | 2015-02-17 17:44:11 -0800 | [diff] [blame] | 10 | * Author: Qiuhan Ding <qiuhanding@cs.ucla.edu> |
Mengjin Yan | aec7074 | 2014-08-25 10:37:45 -0700 | [diff] [blame] | 11 | */ |
| 12 | #ifndef CHRONOCHAT_CHATROOM_INFO_HPP |
| 13 | #define CHRONOCHAT_CHATROOM_INFO_HPP |
| 14 | |
| 15 | #include "common.hpp" |
Qiuhan Ding | 0cfc151 | 2015-02-17 17:44:11 -0800 | [diff] [blame] | 16 | #include "tlv.hpp" |
Mengjin Yan | aec7074 | 2014-08-25 10:37:45 -0700 | [diff] [blame] | 17 | #include <ndn-cxx/name-component.hpp> |
Mengjin Yan | aec7074 | 2014-08-25 10:37:45 -0700 | [diff] [blame] | 18 | #include <ndn-cxx/util/concepts.hpp> |
| 19 | #include <ndn-cxx/encoding/block.hpp> |
| 20 | #include <ndn-cxx/encoding/encoding-buffer.hpp> |
Mengjin Yan | aec7074 | 2014-08-25 10:37:45 -0700 | [diff] [blame] | 21 | #include <boost/concept_check.hpp> |
Qiuhan Ding | 5d98cc5 | 2014-10-30 15:17:53 -0700 | [diff] [blame] | 22 | #include <list> |
Mengjin Yan | aec7074 | 2014-08-25 10:37:45 -0700 | [diff] [blame] | 23 | |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 24 | namespace chronochat { |
Mengjin Yan | aec7074 | 2014-08-25 10:37:45 -0700 | [diff] [blame] | 25 | |
| 26 | /** \brief store a chatroom's information with encode and decode method. |
| 27 | \sa docs/design.rst |
| 28 | */ |
| 29 | |
| 30 | class ChatroomInfo |
| 31 | { |
| 32 | |
| 33 | public: |
| 34 | |
| 35 | class Error : public std::runtime_error |
| 36 | { |
| 37 | public: |
| 38 | explicit |
| 39 | Error(const std::string& what) |
| 40 | : std::runtime_error(what) |
| 41 | { |
| 42 | } |
| 43 | }; |
| 44 | |
Mengjin Yan | aec7074 | 2014-08-25 10:37:45 -0700 | [diff] [blame] | 45 | enum TrustModel { |
| 46 | TRUST_MODEL_HIERARCHICAL = 2, |
| 47 | TRUST_MODEL_WEBOFTRUST = 1, |
| 48 | TRUST_MODEL_NONE = 0 |
| 49 | }; |
| 50 | |
| 51 | public: |
| 52 | |
| 53 | ChatroomInfo(); |
| 54 | |
| 55 | explicit |
| 56 | ChatroomInfo(const Block& chatroomWire); |
| 57 | |
| 58 | const Block& |
| 59 | wireEncode() const; |
| 60 | |
| 61 | void |
| 62 | wireDecode(const Block& chatroomWire); |
| 63 | |
| 64 | const Name::Component& |
| 65 | getName() const; |
| 66 | |
Qiuhan Ding | 5d98cc5 | 2014-10-30 15:17:53 -0700 | [diff] [blame] | 67 | const TrustModel |
| 68 | getTrustModel() const; |
| 69 | |
| 70 | const Name& |
| 71 | getSyncPrefix() const; |
| 72 | |
| 73 | const Name& |
| 74 | getManagerPrefix() const; |
| 75 | |
| 76 | const std::list<Name>& |
| 77 | getParticipants() const; |
| 78 | |
Mengjin Yan | aec7074 | 2014-08-25 10:37:45 -0700 | [diff] [blame] | 79 | void |
| 80 | setName(const Name::Component& name); |
| 81 | |
Qiuhan Ding | 5d98cc5 | 2014-10-30 15:17:53 -0700 | [diff] [blame] | 82 | void |
| 83 | setTrustModel(const TrustModel trustModel); |
Mengjin Yan | aec7074 | 2014-08-25 10:37:45 -0700 | [diff] [blame] | 84 | |
| 85 | void |
| 86 | addParticipant(const Name& participant); |
| 87 | |
Qiuhan Ding | 5d98cc5 | 2014-10-30 15:17:53 -0700 | [diff] [blame] | 88 | void |
| 89 | removeParticipant(const Name& participant); |
Mengjin Yan | aec7074 | 2014-08-25 10:37:45 -0700 | [diff] [blame] | 90 | |
| 91 | void |
Qiuhan Ding | 5d98cc5 | 2014-10-30 15:17:53 -0700 | [diff] [blame] | 92 | setSyncPrefix(const Name& prefix); |
Mengjin Yan | aec7074 | 2014-08-25 10:37:45 -0700 | [diff] [blame] | 93 | |
| 94 | void |
Qiuhan Ding | 5d98cc5 | 2014-10-30 15:17:53 -0700 | [diff] [blame] | 95 | setManager(const Name& manager); |
Mengjin Yan | aec7074 | 2014-08-25 10:37:45 -0700 | [diff] [blame] | 96 | |
| 97 | private: |
| 98 | template<bool T> |
| 99 | size_t |
Alexander Afanasyev | 28eb909 | 2015-06-29 20:15:11 -0700 | [diff] [blame^] | 100 | wireEncode(ndn::EncodingImpl<T>& encoder) const; |
Mengjin Yan | aec7074 | 2014-08-25 10:37:45 -0700 | [diff] [blame] | 101 | |
| 102 | private: |
| 103 | mutable Block m_wire; |
Qiuhan Ding | 5d98cc5 | 2014-10-30 15:17:53 -0700 | [diff] [blame] | 104 | Name::Component m_chatroomName; |
| 105 | std::list<Name> m_participants; |
| 106 | Name m_manager; |
| 107 | Name m_syncPrefix; |
Mengjin Yan | aec7074 | 2014-08-25 10:37:45 -0700 | [diff] [blame] | 108 | TrustModel m_trustModel; |
Mengjin Yan | aec7074 | 2014-08-25 10:37:45 -0700 | [diff] [blame] | 109 | |
| 110 | }; |
| 111 | |
| 112 | inline const Name::Component& |
| 113 | ChatroomInfo::getName() const |
| 114 | { |
Qiuhan Ding | 5d98cc5 | 2014-10-30 15:17:53 -0700 | [diff] [blame] | 115 | return m_chatroomName; |
Mengjin Yan | aec7074 | 2014-08-25 10:37:45 -0700 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | inline const ChatroomInfo::TrustModel |
| 119 | ChatroomInfo::getTrustModel() const |
| 120 | { |
| 121 | return m_trustModel; |
| 122 | } |
| 123 | |
Qiuhan Ding | 5d98cc5 | 2014-10-30 15:17:53 -0700 | [diff] [blame] | 124 | |
| 125 | inline const Name& |
| 126 | ChatroomInfo::getManagerPrefix() const |
| 127 | { |
| 128 | return m_manager; |
| 129 | } |
| 130 | |
| 131 | inline const Name& |
| 132 | ChatroomInfo::getSyncPrefix() const |
| 133 | { |
| 134 | return m_syncPrefix; |
| 135 | } |
| 136 | |
| 137 | inline const std::list<Name>& |
| 138 | ChatroomInfo::getParticipants() const |
| 139 | { |
| 140 | return m_participants; |
| 141 | } |
| 142 | |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 143 | } // namespace chronochat |
Mengjin Yan | aec7074 | 2014-08-25 10:37:45 -0700 | [diff] [blame] | 144 | |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 145 | #endif // CHRONOCHAT_CHATROOM_INFO_HPP |