blob: b5fea14b14fd133c172bf8378fbe5e3a2a01a0a4 [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
12#ifndef CHRONOCHAT_CHATROOM_DISCOVERY_LOGIC_HPP
13#define CHRONOCHAT_CHATROOM_DISCOVERY_LOGIC_HPP
14
15#include "chatroom-info.hpp"
16#include <ndn-cxx/util/scheduler.hpp>
17
18namespace chronos {
19
20class ChatroomDiscoveryLogic : noncopyable
21{
22public:
23 typedef function<void(const ChatroomInfo& chatroomName, bool isAdd)> UpdateCallback;
24
25 typedef std::map<Name::Component, chronos::ChatroomInfo> Chatrooms;
26 static const size_t OFFSET_CHATROOM_NAME;
27 static const size_t DISCOVERY_INTEREST_NAME_SIZE;
28 static const size_t REFRESHING_INTEREST_NAME_SIZE;
29 static const time::milliseconds DEFAULT_REFRESHING_TIMER;
30 static const Name DISCOVERY_PREFIX;
31
32public:
33 explicit
34 ChatroomDiscoveryLogic(shared_ptr<ndn::Face> face,
35 const UpdateCallback& updateCallback);
36
37
38 /** \brief obtain the ongoing chatroom list
39 */
40 const Chatrooms&
41 getChatrooms() const;
42
43 /** \brief add a local chatroom in the ongoing chatroom list
44 */
45 void
46 addLocalChatroom(const ChatroomInfo& chatroom);
47
48 void
49 removeLocalChatroom(const Name::Component& chatroomName);
50
51 /** \brief send discovery interest
52 */
53 void
54 sendDiscoveryInterest();
55
Yingdi Yu6a614442014-10-31 17:42:43 -070056CHRONOCHAT_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Mengjin Yanaec70742014-08-25 10:37:45 -070057 /**
58 */
59 void
60 onDiscoveryInterest(const Name& name, const Interest& interest);
61
62 /**
63 */
64 void
65 onPrefixRegistrationFailed(const Name& name);
66
67 /** \brief schedule another discovery
68 */
69 void
70 onDiscoveryInterestTimeout(const Interest& interest);
71
72 /** \brief send interest to find if the certain chatroom exists
73 */
74 void
75 refreshChatroom(const Name::Component& chatroomName);
76
77 /** \brief copy the contact from the participants of the chatroom to contacts of the chatroom
78 */
79 void
80 addContacts(ChatroomInfo& chatroom);
81
Yingdi Yu6a614442014-10-31 17:42:43 -070082CHRONOCHAT_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Mengjin Yanaec70742014-08-25 10:37:45 -070083
84 /** \brief erase the chatroom from the ongoing chatroom list
85 */
86 void
87 onRefreshingInterestTimeout(const Interest& interest);
88
89 /** \brief operate the chatroom data and schedule discovery and refreshing process
90 */
91 void
92 onReceiveData(const ndn::Interest& interest, const ndn::Data& data, const bool isRefreshing);
93
94private:
95 static const time::seconds m_discoveryInterval;
96
97 shared_ptr<ndn::Face> m_face;
98
99 ndn::KeyChain m_keyChain;
100
101 Chatrooms m_chatrooms;
102 Chatrooms m_localChatrooms;
103
104 ndn::Scheduler m_scheduler;
105
106 UpdateCallback m_onUpdate;
107
108};
109
110inline const ChatroomDiscoveryLogic::Chatrooms&
111ChatroomDiscoveryLogic::getChatrooms() const
112{
113 return m_chatrooms;
114}
115
116} // namespace chronos
117
118#endif // CHRONOCHAT_CHATROOM_DISCOVERY_LOGIC_HPP