blob: a449aa42b91914296fc894c2580f5a492454f40f [file] [log] [blame]
Yingdi Yu2c9e7712014-10-20 11:55:05 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2013, Regents of the University of California
4 *
5 * BSD license, See the LICENSE file for more information
6 *
7 * Author: Yingdi Yu <yingdi@cs.ucla.edu>
8 */
9
10#ifndef CHRONOCHAT_CONTROLLER_BACKEND_HPP
11#define CHRONOCHAT_CONTROLLER_BACKEND_HPP
12
Qiuhan Dingba3e57a2015-01-08 19:07:39 -080013#include <QString>
Yingdi Yu2c9e7712014-10-20 11:55:05 -070014#include <QThread>
15#include <QStringList>
16#include <QMutex>
17
18#ifndef Q_MOC_RUN
19#include "common.hpp"
20#include "contact-manager.hpp"
21#include "invitation.hpp"
22#include "validator-invitation.hpp"
23#include <ndn-cxx/security/key-chain.hpp>
Qiuhan Dingba3e57a2015-01-08 19:07:39 -080024#include <ndn-cxx/util/in-memory-storage-persistent.hpp>
Yingdi Yu2c9e7712014-10-20 11:55:05 -070025#endif
26
Yingdi Yueb692ac2015-02-10 18:46:18 -080027namespace chronochat {
Yingdi Yu2c9e7712014-10-20 11:55:05 -070028
29class ControllerBackend : public QThread
30{
31 Q_OBJECT
32
33public:
34 ControllerBackend(QObject* parent = 0);
35
36 ~ControllerBackend();
37
38 ContactManager*
39 getContactManager()
40 {
41 return &m_contactManager;
42 }
43
44protected:
45 void
46 run();
47
48private:
49 void
50 setInvitationListener();
51
52 ndn::Name
53 getInvitationRoutingPrefix();
54
55 void
56 onInvitationPrefixReset();
57
58 void
59 onInvitationPrefixResetFailed(const std::string& failInfo);
60
61 void
62 onInvitationInterest(const ndn::Name& prefix, const ndn::Interest& interest,
63 size_t routingPrefixOffset);
64
65 void
Qiuhan Dingba3e57a2015-01-08 19:07:39 -080066 onInvitationRequestInterest(const ndn::Name& prefix, const ndn::Interest& interest,
67 size_t routingPrefixOffset);
68
69 void
Yingdi Yu2c9e7712014-10-20 11:55:05 -070070 onInvitationRegisterFailed(const Name& prefix, const std::string& failInfo);
71
72 void
73 onInvitationValidated(const shared_ptr<const Interest>& interest);
74
75 void
76 onInvitationValidationFailed(const shared_ptr<const Interest>& interest,
77 std::string failureInfo);
78
79 void
80 onLocalPrefix(const Interest& interest, Data& data);
81
82 void
83 onLocalPrefixTimeout(const Interest& interest);
84
85 void
86 updateLocalPrefix(const Name& localPrefix);
87
Qiuhan Dingba3e57a2015-01-08 19:07:39 -080088 void
89 onRequestResponse(const Interest& interest, Data& data);
90
91 void
92 onRequestTimeout(const Interest& interest, int& resendTimes);
93
Yingdi Yu2c9e7712014-10-20 11:55:05 -070094signals:
95 void
96 identityUpdated(const QString& identity);
97
98 void
99 localPrefixUpdated(const QString& localPrefix);
100
101 void
Qiuhan Dingba3e57a2015-01-08 19:07:39 -0800102 invitationValidated(QString alias, QString chatroom, ndn::Name invitationINterest);
103
104 void
105 invitationRequestReceived(QString alias, QString chatroom, ndn::Name invitationRequestInterest);
Yingdi Yu2c9e7712014-10-20 11:55:05 -0700106
107 void
Yingdi Yueb692ac2015-02-10 18:46:18 -0800108 startChatroomOnInvitation(chronochat::Invitation invitation, bool secured);
Yingdi Yu2c9e7712014-10-20 11:55:05 -0700109
Qiuhan Dingba3e57a2015-01-08 19:07:39 -0800110 void
111 startChatroom(const QString& chatroomName, bool secured);
112
113 void
114 invitationRequestResult(const std::string& msg);
115
Yingdi Yu2c9e7712014-10-20 11:55:05 -0700116public slots:
117 void
118 shutdown();
119
120 void
121 addChatroom(QString chatroom);
122
123 void
124 removeChatroom(QString chatroom);
125
126 void
127 onUpdateLocalPrefixAction();
128
129 void
130 onIdentityChanged(const QString& identity);
131
132 void
133 onInvitationResponded(const ndn::Name& invitationName, bool accepted);
134
Qiuhan Dingba3e57a2015-01-08 19:07:39 -0800135 void
136 onInvitationRequestResponded(const ndn::Name& invitationName, bool accepted);
137
138 void
139 onSendInvitationRequest(const QString& chatroomName, const QString& prefix);
140
Yingdi Yu2c9e7712014-10-20 11:55:05 -0700141private slots:
142 void
143 onContactIdListReady(const QStringList& list);
144
145private:
146 ndn::Face m_face;
147
148 Name m_identity; //TODO: set/get
149
150 Name m_localPrefix;
151
152 // Contact Manager
153 ContactManager m_contactManager;
154
155 // Security related;
156 ndn::KeyChain m_keyChain;
157 ValidatorInvitation m_validator;
158
159 // RegisteredPrefixId
160 const ndn::RegisteredPrefixId* m_invitationListenerId;
Qiuhan Dingba3e57a2015-01-08 19:07:39 -0800161 const ndn::RegisteredPrefixId* m_requestListenerId;
Yingdi Yu2c9e7712014-10-20 11:55:05 -0700162
163 // ChatRoomList
164 QStringList m_chatDialogList;
165
166 QMutex m_mutex;
Qiuhan Dingba3e57a2015-01-08 19:07:39 -0800167
168 ndn::util::InMemoryStoragePersistent m_ims;
Yingdi Yu2c9e7712014-10-20 11:55:05 -0700169};
170
Yingdi Yueb692ac2015-02-10 18:46:18 -0800171} // namespace chronochat
Yingdi Yu2c9e7712014-10-20 11:55:05 -0700172
173#endif // CHRONOCHAT_CONTROLLER_BACKEND_HPP