Yingdi Yu | 2c9e771 | 2014-10-20 11:55:05 -0700 | [diff] [blame] | 1 | /* -*- 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 Ding | ba3e57a | 2015-01-08 19:07:39 -0800 | [diff] [blame^] | 13 | #include <QString> |
Yingdi Yu | 2c9e771 | 2014-10-20 11:55:05 -0700 | [diff] [blame] | 14 | #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 Ding | ba3e57a | 2015-01-08 19:07:39 -0800 | [diff] [blame^] | 24 | #include <ndn-cxx/util/in-memory-storage-persistent.hpp> |
Yingdi Yu | 2c9e771 | 2014-10-20 11:55:05 -0700 | [diff] [blame] | 25 | #endif |
| 26 | |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 27 | namespace chronochat { |
Yingdi Yu | 2c9e771 | 2014-10-20 11:55:05 -0700 | [diff] [blame] | 28 | |
| 29 | class ControllerBackend : public QThread |
| 30 | { |
| 31 | Q_OBJECT |
| 32 | |
| 33 | public: |
| 34 | ControllerBackend(QObject* parent = 0); |
| 35 | |
| 36 | ~ControllerBackend(); |
| 37 | |
| 38 | ContactManager* |
| 39 | getContactManager() |
| 40 | { |
| 41 | return &m_contactManager; |
| 42 | } |
| 43 | |
| 44 | protected: |
| 45 | void |
| 46 | run(); |
| 47 | |
| 48 | private: |
| 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 Ding | ba3e57a | 2015-01-08 19:07:39 -0800 | [diff] [blame^] | 66 | onInvitationRequestInterest(const ndn::Name& prefix, const ndn::Interest& interest, |
| 67 | size_t routingPrefixOffset); |
| 68 | |
| 69 | void |
Yingdi Yu | 2c9e771 | 2014-10-20 11:55:05 -0700 | [diff] [blame] | 70 | 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 Ding | ba3e57a | 2015-01-08 19:07:39 -0800 | [diff] [blame^] | 88 | void |
| 89 | onRequestResponse(const Interest& interest, Data& data); |
| 90 | |
| 91 | void |
| 92 | onRequestTimeout(const Interest& interest, int& resendTimes); |
| 93 | |
Yingdi Yu | 2c9e771 | 2014-10-20 11:55:05 -0700 | [diff] [blame] | 94 | signals: |
| 95 | void |
| 96 | identityUpdated(const QString& identity); |
| 97 | |
| 98 | void |
| 99 | localPrefixUpdated(const QString& localPrefix); |
| 100 | |
| 101 | void |
Qiuhan Ding | ba3e57a | 2015-01-08 19:07:39 -0800 | [diff] [blame^] | 102 | invitationValidated(QString alias, QString chatroom, ndn::Name invitationINterest); |
| 103 | |
| 104 | void |
| 105 | invitationRequestReceived(QString alias, QString chatroom, ndn::Name invitationRequestInterest); |
Yingdi Yu | 2c9e771 | 2014-10-20 11:55:05 -0700 | [diff] [blame] | 106 | |
| 107 | void |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 108 | startChatroomOnInvitation(chronochat::Invitation invitation, bool secured); |
Yingdi Yu | 2c9e771 | 2014-10-20 11:55:05 -0700 | [diff] [blame] | 109 | |
Qiuhan Ding | ba3e57a | 2015-01-08 19:07:39 -0800 | [diff] [blame^] | 110 | void |
| 111 | startChatroom(const QString& chatroomName, bool secured); |
| 112 | |
| 113 | void |
| 114 | invitationRequestResult(const std::string& msg); |
| 115 | |
Yingdi Yu | 2c9e771 | 2014-10-20 11:55:05 -0700 | [diff] [blame] | 116 | public 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 Ding | ba3e57a | 2015-01-08 19:07:39 -0800 | [diff] [blame^] | 135 | void |
| 136 | onInvitationRequestResponded(const ndn::Name& invitationName, bool accepted); |
| 137 | |
| 138 | void |
| 139 | onSendInvitationRequest(const QString& chatroomName, const QString& prefix); |
| 140 | |
Yingdi Yu | 2c9e771 | 2014-10-20 11:55:05 -0700 | [diff] [blame] | 141 | private slots: |
| 142 | void |
| 143 | onContactIdListReady(const QStringList& list); |
| 144 | |
| 145 | private: |
| 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 Ding | ba3e57a | 2015-01-08 19:07:39 -0800 | [diff] [blame^] | 161 | const ndn::RegisteredPrefixId* m_requestListenerId; |
Yingdi Yu | 2c9e771 | 2014-10-20 11:55:05 -0700 | [diff] [blame] | 162 | |
| 163 | // ChatRoomList |
| 164 | QStringList m_chatDialogList; |
| 165 | |
| 166 | QMutex m_mutex; |
Qiuhan Ding | ba3e57a | 2015-01-08 19:07:39 -0800 | [diff] [blame^] | 167 | |
| 168 | ndn::util::InMemoryStoragePersistent m_ims; |
Yingdi Yu | 2c9e771 | 2014-10-20 11:55:05 -0700 | [diff] [blame] | 169 | }; |
| 170 | |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 171 | } // namespace chronochat |
Yingdi Yu | 2c9e771 | 2014-10-20 11:55:05 -0700 | [diff] [blame] | 172 | |
| 173 | #endif // CHRONOCHAT_CONTROLLER_BACKEND_HPP |