blob: 80b076bbd08ffc932325abb8c314afa43391ffef [file] [log] [blame]
Mengjin Yanaec70742014-08-25 10:37:45 -07001/* -*- 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>
Qiuhan Ding5d98cc52014-10-30 15:17:53 -070025#include <list>
Mengjin Yanaec70742014-08-25 10:37:45 -070026
Yingdi Yueb692ac2015-02-10 18:46:18 -080027namespace chronochat {
Mengjin Yanaec70742014-08-25 10:37:45 -070028
29/** \brief store a chatroom's information with encode and decode method.
30 \sa docs/design.rst
31 */
32
33class ChatroomInfo
34{
35
36public:
37
38 class Error : public std::runtime_error
39 {
40 public:
41 explicit
42 Error(const std::string& what)
43 : std::runtime_error(what)
44 {
45 }
46 };
47
Mengjin Yanaec70742014-08-25 10:37:45 -070048 enum TrustModel {
49 TRUST_MODEL_HIERARCHICAL = 2,
50 TRUST_MODEL_WEBOFTRUST = 1,
51 TRUST_MODEL_NONE = 0
52 };
53
54public:
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
Qiuhan Ding5d98cc52014-10-30 15:17:53 -070070 const TrustModel
71 getTrustModel() const;
72
73 const Name&
74 getSyncPrefix() const;
75
76 const Name&
77 getManagerPrefix() const;
78
79 const std::list<Name>&
80 getParticipants() const;
81
Mengjin Yanaec70742014-08-25 10:37:45 -070082 void
83 setName(const Name::Component& name);
84
Qiuhan Ding5d98cc52014-10-30 15:17:53 -070085 void
86 setTrustModel(const TrustModel trustModel);
Mengjin Yanaec70742014-08-25 10:37:45 -070087
88 void
89 addParticipant(const Name& participant);
90
Qiuhan Ding5d98cc52014-10-30 15:17:53 -070091 void
92 removeParticipant(const Name& participant);
Mengjin Yanaec70742014-08-25 10:37:45 -070093
94 void
Qiuhan Ding5d98cc52014-10-30 15:17:53 -070095 setSyncPrefix(const Name& prefix);
Mengjin Yanaec70742014-08-25 10:37:45 -070096
97 void
Qiuhan Ding5d98cc52014-10-30 15:17:53 -070098 setManager(const Name& manager);
Mengjin Yanaec70742014-08-25 10:37:45 -070099
100private:
101 template<bool T>
102 size_t
103 wireEncode(ndn::EncodingImpl<T>& block) const;
104
105private:
106 mutable Block m_wire;
Qiuhan Ding5d98cc52014-10-30 15:17:53 -0700107 Name::Component m_chatroomName;
108 std::list<Name> m_participants;
109 Name m_manager;
110 Name m_syncPrefix;
Mengjin Yanaec70742014-08-25 10:37:45 -0700111 TrustModel m_trustModel;
Mengjin Yanaec70742014-08-25 10:37:45 -0700112
113};
114
115inline const Name::Component&
116ChatroomInfo::getName() const
117{
Qiuhan Ding5d98cc52014-10-30 15:17:53 -0700118 return m_chatroomName;
Mengjin Yanaec70742014-08-25 10:37:45 -0700119}
120
121inline const ChatroomInfo::TrustModel
122ChatroomInfo::getTrustModel() const
123{
124 return m_trustModel;
125}
126
Qiuhan Ding5d98cc52014-10-30 15:17:53 -0700127
128inline const Name&
129ChatroomInfo::getManagerPrefix() const
130{
131 return m_manager;
132}
133
134inline const Name&
135ChatroomInfo::getSyncPrefix() const
136{
137 return m_syncPrefix;
138}
139
140inline const std::list<Name>&
141ChatroomInfo::getParticipants() const
142{
143 return m_participants;
144}
145
Mengjin Yanaec70742014-08-25 10:37:45 -0700146BOOST_CONCEPT_ASSERT((ndn::WireEncodable<ChatroomInfo>));
147BOOST_CONCEPT_ASSERT((ndn::WireDecodable<ChatroomInfo>));
148
149
Yingdi Yueb692ac2015-02-10 18:46:18 -0800150} // namespace chronochat
Mengjin Yanaec70742014-08-25 10:37:45 -0700151
Yingdi Yueb692ac2015-02-10 18:46:18 -0800152#endif // CHRONOCHAT_CHATROOM_INFO_HPP