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> |
| 10 | */ |
| 11 | #ifndef CHRONOCHAT_CHATROOM_INFO_HPP |
| 12 | #define CHRONOCHAT_CHATROOM_INFO_HPP |
| 13 | |
| 14 | #include "common.hpp" |
| 15 | #include "chatroom-tlv.hpp" |
| 16 | #include <ndn-cxx/face.hpp> |
| 17 | #include <ndn-cxx/security/key-chain.hpp> |
| 18 | #include <ndn-cxx/name-component.hpp> |
| 19 | #include <ndn-cxx/util/time.hpp> |
| 20 | #include <ndn-cxx/util/concepts.hpp> |
| 21 | #include <ndn-cxx/encoding/block.hpp> |
| 22 | #include <ndn-cxx/encoding/encoding-buffer.hpp> |
| 23 | #include <ndn-cxx/exclude.hpp> |
| 24 | #include <boost/concept_check.hpp> |
| 25 | |
| 26 | namespace chronos { |
| 27 | |
| 28 | /** \brief store a chatroom's information with encode and decode method. |
| 29 | \sa docs/design.rst |
| 30 | */ |
| 31 | |
| 32 | class ChatroomInfo |
| 33 | { |
| 34 | |
| 35 | public: |
| 36 | |
| 37 | class Error : public std::runtime_error |
| 38 | { |
| 39 | public: |
| 40 | explicit |
| 41 | Error(const std::string& what) |
| 42 | : std::runtime_error(what) |
| 43 | { |
| 44 | } |
| 45 | }; |
| 46 | |
| 47 | |
| 48 | enum TrustModel { |
| 49 | TRUST_MODEL_HIERARCHICAL = 2, |
| 50 | TRUST_MODEL_WEBOFTRUST = 1, |
| 51 | TRUST_MODEL_NONE = 0 |
| 52 | }; |
| 53 | |
| 54 | public: |
| 55 | |
| 56 | ChatroomInfo(); |
| 57 | |
| 58 | explicit |
| 59 | ChatroomInfo(const Block& chatroomWire); |
| 60 | |
| 61 | const Block& |
| 62 | wireEncode() const; |
| 63 | |
| 64 | void |
| 65 | wireDecode(const Block& chatroomWire); |
| 66 | |
| 67 | const Name::Component& |
| 68 | getName() const; |
| 69 | |
| 70 | void |
| 71 | setName(const Name::Component& name); |
| 72 | |
| 73 | const std::vector<Name>& |
| 74 | getParticipants() const; |
| 75 | |
| 76 | void |
| 77 | addParticipant(const Name& participant); |
| 78 | |
| 79 | const std::vector<Name>& |
| 80 | getContacts() const; |
| 81 | |
| 82 | void |
| 83 | addContact(const Name& contact); |
| 84 | |
| 85 | const TrustModel |
| 86 | getTrustModel() const; |
| 87 | |
| 88 | void |
| 89 | setTrustModel(const TrustModel trustModel); |
| 90 | |
| 91 | private: |
| 92 | template<bool T> |
| 93 | size_t |
| 94 | wireEncode(ndn::EncodingImpl<T>& block) const; |
| 95 | |
| 96 | private: |
| 97 | mutable Block m_wire; |
| 98 | Name::Component m_name; |
| 99 | std::vector<Name> m_participants; |
| 100 | TrustModel m_trustModel; |
| 101 | std::vector<Name> m_contacts; |
| 102 | |
| 103 | }; |
| 104 | |
| 105 | inline const Name::Component& |
| 106 | ChatroomInfo::getName() const |
| 107 | { |
| 108 | return m_name; |
| 109 | } |
| 110 | |
| 111 | inline const std::vector<Name>& |
| 112 | ChatroomInfo::getParticipants() const |
| 113 | { |
| 114 | return m_participants; |
| 115 | } |
| 116 | |
| 117 | inline const std::vector<Name>& |
| 118 | ChatroomInfo::getContacts() const |
| 119 | { |
| 120 | return m_contacts; |
| 121 | } |
| 122 | |
| 123 | inline const ChatroomInfo::TrustModel |
| 124 | ChatroomInfo::getTrustModel() const |
| 125 | { |
| 126 | return m_trustModel; |
| 127 | } |
| 128 | |
| 129 | BOOST_CONCEPT_ASSERT((ndn::WireEncodable<ChatroomInfo>)); |
| 130 | BOOST_CONCEPT_ASSERT((ndn::WireDecodable<ChatroomInfo>)); |
| 131 | |
| 132 | |
| 133 | } // namespace chronos |
| 134 | |
| 135 | #endif //CHRONOCHAT_CHATROOM_INFO_HPP |