blob: 81e0fde38cd16c48b6f5699d96347b2dd554491a [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>
Qiuhan Ding0cfc1512015-02-17 17:44:11 -080010 * Author: Qiuhan Ding <qiuhanding@cs.ucla.edu>
Mengjin Yanaec70742014-08-25 10:37:45 -070011 */
12#ifndef CHRONOCHAT_CHATROOM_INFO_HPP
13#define CHRONOCHAT_CHATROOM_INFO_HPP
14
15#include "common.hpp"
Qiuhan Ding0cfc1512015-02-17 17:44:11 -080016#include "tlv.hpp"
Mengjin Yanaec70742014-08-25 10:37:45 -070017#include <ndn-cxx/name-component.hpp>
Mengjin Yanaec70742014-08-25 10:37:45 -070018#include <ndn-cxx/util/concepts.hpp>
19#include <ndn-cxx/encoding/block.hpp>
20#include <ndn-cxx/encoding/encoding-buffer.hpp>
Mengjin Yanaec70742014-08-25 10:37:45 -070021#include <boost/concept_check.hpp>
Qiuhan Ding5d98cc52014-10-30 15:17:53 -070022#include <list>
Mengjin Yanaec70742014-08-25 10:37:45 -070023
Yingdi Yueb692ac2015-02-10 18:46:18 -080024namespace chronochat {
Mengjin Yanaec70742014-08-25 10:37:45 -070025
26/** \brief store a chatroom's information with encode and decode method.
27 \sa docs/design.rst
28 */
29
30class ChatroomInfo
31{
32
33public:
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 Yanaec70742014-08-25 10:37:45 -070045 enum TrustModel {
46 TRUST_MODEL_HIERARCHICAL = 2,
47 TRUST_MODEL_WEBOFTRUST = 1,
48 TRUST_MODEL_NONE = 0
49 };
50
51public:
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 Ding5d98cc52014-10-30 15:17:53 -070067 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 Yanaec70742014-08-25 10:37:45 -070079 void
80 setName(const Name::Component& name);
81
Qiuhan Ding5d98cc52014-10-30 15:17:53 -070082 void
83 setTrustModel(const TrustModel trustModel);
Mengjin Yanaec70742014-08-25 10:37:45 -070084
85 void
86 addParticipant(const Name& participant);
87
Qiuhan Ding5d98cc52014-10-30 15:17:53 -070088 void
89 removeParticipant(const Name& participant);
Mengjin Yanaec70742014-08-25 10:37:45 -070090
91 void
Qiuhan Ding5d98cc52014-10-30 15:17:53 -070092 setSyncPrefix(const Name& prefix);
Mengjin Yanaec70742014-08-25 10:37:45 -070093
94 void
Qiuhan Ding5d98cc52014-10-30 15:17:53 -070095 setManager(const Name& manager);
Mengjin Yanaec70742014-08-25 10:37:45 -070096
97private:
Varun Patil3d850902020-11-23 12:19:14 +053098 template<ndn::encoding::Tag T>
Mengjin Yanaec70742014-08-25 10:37:45 -070099 size_t
Alexander Afanasyev28eb9092015-06-29 20:15:11 -0700100 wireEncode(ndn::EncodingImpl<T>& encoder) const;
Mengjin Yanaec70742014-08-25 10:37:45 -0700101
102private:
103 mutable Block m_wire;
Qiuhan Ding5d98cc52014-10-30 15:17:53 -0700104 Name::Component m_chatroomName;
105 std::list<Name> m_participants;
106 Name m_manager;
107 Name m_syncPrefix;
Mengjin Yanaec70742014-08-25 10:37:45 -0700108 TrustModel m_trustModel;
Mengjin Yanaec70742014-08-25 10:37:45 -0700109
110};
111
112inline const Name::Component&
113ChatroomInfo::getName() const
114{
Qiuhan Ding5d98cc52014-10-30 15:17:53 -0700115 return m_chatroomName;
Mengjin Yanaec70742014-08-25 10:37:45 -0700116}
117
118inline const ChatroomInfo::TrustModel
119ChatroomInfo::getTrustModel() const
120{
121 return m_trustModel;
122}
123
Qiuhan Ding5d98cc52014-10-30 15:17:53 -0700124
125inline const Name&
126ChatroomInfo::getManagerPrefix() const
127{
128 return m_manager;
129}
130
131inline const Name&
132ChatroomInfo::getSyncPrefix() const
133{
134 return m_syncPrefix;
135}
136
137inline const std::list<Name>&
138ChatroomInfo::getParticipants() const
139{
140 return m_participants;
141}
142
Yingdi Yueb692ac2015-02-10 18:46:18 -0800143} // namespace chronochat
Mengjin Yanaec70742014-08-25 10:37:45 -0700144
Yingdi Yueb692ac2015-02-10 18:46:18 -0800145#endif // CHRONOCHAT_CHATROOM_INFO_HPP