blob: be6c499900803a4d489d7186e7cbc0c24e3772d6 [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
13#include <QThread>
14#include <QStringList>
15#include <QMutex>
16
17#ifndef Q_MOC_RUN
18#include "common.hpp"
19#include "contact-manager.hpp"
20#include "invitation.hpp"
21#include "validator-invitation.hpp"
22#include <ndn-cxx/security/key-chain.hpp>
23#endif
24
Yingdi Yueb692ac2015-02-10 18:46:18 -080025namespace chronochat {
Yingdi Yu2c9e7712014-10-20 11:55:05 -070026
27class ControllerBackend : public QThread
28{
29 Q_OBJECT
30
31public:
32 ControllerBackend(QObject* parent = 0);
33
34 ~ControllerBackend();
35
36 ContactManager*
37 getContactManager()
38 {
39 return &m_contactManager;
40 }
41
42protected:
43 void
44 run();
45
46private:
47 void
48 setInvitationListener();
49
50 ndn::Name
51 getInvitationRoutingPrefix();
52
53 void
54 onInvitationPrefixReset();
55
56 void
57 onInvitationPrefixResetFailed(const std::string& failInfo);
58
59 void
60 onInvitationInterest(const ndn::Name& prefix, const ndn::Interest& interest,
61 size_t routingPrefixOffset);
62
63 void
64 onInvitationRegisterFailed(const Name& prefix, const std::string& failInfo);
65
66 void
67 onInvitationValidated(const shared_ptr<const Interest>& interest);
68
69 void
70 onInvitationValidationFailed(const shared_ptr<const Interest>& interest,
71 std::string failureInfo);
72
73 void
74 onLocalPrefix(const Interest& interest, Data& data);
75
76 void
77 onLocalPrefixTimeout(const Interest& interest);
78
79 void
80 updateLocalPrefix(const Name& localPrefix);
81
82signals:
83 void
84 identityUpdated(const QString& identity);
85
86 void
87 localPrefixUpdated(const QString& localPrefix);
88
89 void
90 invitaionValidated(QString alias, QString chatroom, ndn::Name invitationINterest);
91
92 void
Yingdi Yueb692ac2015-02-10 18:46:18 -080093 startChatroomOnInvitation(chronochat::Invitation invitation, bool secured);
Yingdi Yu2c9e7712014-10-20 11:55:05 -070094
95public slots:
96 void
97 shutdown();
98
99 void
100 addChatroom(QString chatroom);
101
102 void
103 removeChatroom(QString chatroom);
104
105 void
106 onUpdateLocalPrefixAction();
107
108 void
109 onIdentityChanged(const QString& identity);
110
111 void
112 onInvitationResponded(const ndn::Name& invitationName, bool accepted);
113
114private slots:
115 void
116 onContactIdListReady(const QStringList& list);
117
118private:
119 ndn::Face m_face;
120
121 Name m_identity; //TODO: set/get
122
123 Name m_localPrefix;
124
125 // Contact Manager
126 ContactManager m_contactManager;
127
128 // Security related;
129 ndn::KeyChain m_keyChain;
130 ValidatorInvitation m_validator;
131
132 // RegisteredPrefixId
133 const ndn::RegisteredPrefixId* m_invitationListenerId;
134
135 // ChatRoomList
136 QStringList m_chatDialogList;
137
138 QMutex m_mutex;
139};
140
Yingdi Yueb692ac2015-02-10 18:46:18 -0800141} // namespace chronochat
Yingdi Yu2c9e7712014-10-20 11:55:05 -0700142
143#endif // CHRONOCHAT_CONTROLLER_BACKEND_HPP