summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortg(x) <*@tg-x.net>2016-02-06 23:31:20 +0100
committertg(x) <*@tg-x.net>2016-02-06 23:31:20 +0100
commit11a0a496f7f3f78ca30f088adb7154235724f93c (patch)
treee976fe8380203b6ff164abce47fcc9c7b328d1d2
parent9187bc152316c1563c2e0852ded5c17261df5860 (diff)
downloadsecushare-11a0a496f7f3f78ca30f088adb7154235724f93c.tar.gz
secushare-11a0a496f7f3f78ca30f088adb7154235724f93c.zip
shutdown & cleanup
-rw-r--r--qml/About.qml13
-rw-r--r--qml/main.qml7
-rw-r--r--src/app.cpp47
-rw-r--r--src/app.h13
-rw-r--r--src/gnunet/gnunet.cpp63
-rw-r--r--src/gnunet/gnunet.h40
-rw-r--r--src/main.cpp5
-rw-r--r--src/social/host.cpp10
-rw-r--r--src/social/host.h2
-rw-r--r--src/social/place.cpp6
-rw-r--r--src/social/socialapp.cpp21
11 files changed, 121 insertions, 106 deletions
diff --git a/qml/About.qml b/qml/About.qml
index 9b28e48..c03741d 100644
--- a/qml/About.qml
+++ b/qml/About.qml
@@ -1,5 +1,5 @@
1import QtQuick.Window 2.1;
2import QtQuick 2.2 1import QtQuick 2.2
2import QtQuick.Window 2.1
3import QtQuick.Controls 1.1 3import QtQuick.Controls 1.1
4import QtQuick.Layouts 1.1 4import QtQuick.Layouts 1.1
5 5
@@ -11,7 +11,6 @@ Window {
11 height: 400; 11 height: 400;
12 id: aboutWnd 12 id: aboutWnd
13 13
14
15 RowLayout{ 14 RowLayout{
16 anchors.fill: parent 15 anchors.fill: parent
17 anchors.margins: 10 16 anchors.margins: 10
@@ -21,14 +20,11 @@ Window {
21 Add designed by Factorio.us collective from the Noun Project 20 Add designed by Factorio.us collective from the Noun Project
22 Send designed by Javier Sánchez - javyliu from the thenounproject.com 21 Send designed by Javier Sánchez - javyliu from the thenounproject.com
23 Gear designed by P.J. Onori from the thenounproject.com 22 Gear designed by P.J. Onori from the thenounproject.com
24 GLYPHICONS FREE are released under the Creative Commons Attribution 3.0 Unported (CC BY 3.0) (http://glyphicons.com/). 23 GLYPHICONS FREE are released under the Creative Commons Attribution 3.0 Unported (CC BY 3.0) (http://glyphicons.com/)."
25"
26
27 } 24 }
28 25
29
30 Button{ 26 Button{
31 text: "Ok" 27 text: "OK"
32 onPressedChanged: { 28 onPressedChanged: {
33 aboutWnd.close(); 29 aboutWnd.close();
34 } 30 }
@@ -36,6 +32,3 @@ Window {
36 } 32 }
37 33
38} 34}
39
40
41
diff --git a/qml/main.qml b/qml/main.qml
index 83cec0c..fee82da 100644
--- a/qml/main.qml
+++ b/qml/main.qml
@@ -6,7 +6,12 @@ import QtQuick.Controls.Styles 1.2
6 6
7import secushare 1.0 7import secushare 1.0
8 8
9Window { 9ApplicationWindow {
10 onClosing: {
11 close.accepted = false
12 App.close()
13 }
14
10 id: root 15 id: root
11 16
12 width: 1000 17 width: 1000
diff --git a/src/app.cpp b/src/app.cpp
index 73e6ea8..e20de4a 100644
--- a/src/app.cpp
+++ b/src/app.cpp
@@ -33,12 +33,6 @@ App::App (QObject * parent)
33 33
34App::~App () 34App::~App ()
35{ 35{
36 if (m_gnunet)
37 {
38 delete m_gnunet;
39 m_gnunet = NULL;
40 m_gnunetThread->exit ();
41 }
42} 36}
43 37
44 38
@@ -49,23 +43,30 @@ App::~App ()
49void 43void
50App::startGnuNet () 44App::startGnuNet ()
51{ 45{
52 //Create the GnuNet object
53 m_gnunet = new GnuNet (); 46 m_gnunet = new GnuNet ();
54
55 //New thread where the Gnunet will be run on.
56 m_gnunetThread = new QThread (); 47 m_gnunetThread = new QThread ();
57
58 m_gnunet->moveToThread (m_gnunetThread); 48 m_gnunet->moveToThread (m_gnunetThread);
59 49
60 // Call the start function after our thread is ready to run 50 connect (m_gnunetThread, SIGNAL (started ()),
61 connect (m_gnunetThread, &QThread::started, 51 m_gnunet, SLOT (start ()));
62 m_gnunet, &GnuNet::start);
63
64 m_gnunetThread->start ();
65 52
66 connect (m_gnunet, &GnuNet::connectedChanged, 53 connect (m_gnunet, &GnuNet::connectedChanged,
67 this, &App::setConnected, 54 this, &App::setConnected, Qt::QueuedConnection);
68 Qt::QueuedConnection); 55
56
57 connect(m_gnunet, SIGNAL(stopped()),
58 m_gnunet, SLOT(deleteLater()));
59
60 connect(m_gnunet, SIGNAL(stopped()),
61 m_gnunetThread, SLOT(quit()));
62
63 connect(m_gnunetThread, SIGNAL(finished()),
64 m_gnunetThread, SLOT(deleteLater()));
65
66 connect(m_gnunetThread, SIGNAL(finished()),
67 qApp, SLOT(quit()));
68
69 m_gnunetThread->start ();
69} 70}
70 71
71 72
@@ -163,7 +164,8 @@ App::setupTray ()
163 // add a horizontal line to the menu 164 // add a horizontal line to the menu
164 m_trayMenu->addSeparator (); 165 m_trayMenu->addSeparator ();
165 m_trayCloseAction = m_trayMenu->addAction ("Close"); 166 m_trayCloseAction = m_trayMenu->addAction ("Close");
166 connect (m_trayCloseAction, &QAction::triggered, this, &App::close); 167 connect (m_trayCloseAction, &QAction::triggered,
168 this, &App::close);
167 169
168 // same as above 170 // same as above
169 m_tray = new QSystemTrayIcon (QIcon (":/assets/icon.ico"), theWindow); 171 m_tray = new QSystemTrayIcon (QIcon (":/assets/icon.ico"), theWindow);
@@ -186,7 +188,7 @@ App::trayActivated (QSystemTrayIcon::ActivationReason reason)
186 } 188 }
187 else 189 else
188 { 190 {
189 onClose (); 191 hide ();
190 } 192 }
191 } 193 }
192} 194}
@@ -206,10 +208,10 @@ App::setTrayMessage (QString place, QString message)
206 208
207 209
208/** 210/**
209 * Recivied close signal 211 * Recieved close signal
210 */ 212 */
211void 213void
212App::onClose () 214App::hide ()
213{ 215{
214 theWindow->hide (); 216 theWindow->hide ();
215} 217}
@@ -221,6 +223,5 @@ App::onClose ()
221void 223void
222App::close () 224App::close ()
223{ 225{
224 //setAlive(false); 226 m_gnunet->stop ();
225 QApplication::quit ();
226} 227}
diff --git a/src/app.h b/src/app.h
index d4cd978..8bfa4fa 100644
--- a/src/app.h
+++ b/src/app.h
@@ -65,11 +65,12 @@ public:
65 65
66 SocialApp *social () const 66 SocialApp *social () const
67 { 67 {
68 return m_gnunet->social (); 68 return m_gnunet ? m_gnunet->social () : NULL;
69 } 69 }
70 70
71 void setupTray (); 71 void setupTray ();
72 Q_INVOKABLE void onClose (); 72 Q_INVOKABLE void hide ();
73 Q_INVOKABLE void close ();
73 74
74 void setConnected (bool connected); 75 void setConnected (bool connected);
75 76
@@ -97,13 +98,13 @@ private:
97 void 98 void
98 startGnuNet (); 99 startGnuNet ();
99 100
100 void 101 signals:
101 close ();
102 102
103signals:
104 void connectedChanged (bool connected); 103 void connectedChanged (bool connected);
105 104
106 public slots:void trayActivated (QSystemTrayIcon::ActivationReason reason); 105 public slots:
106
107 void trayActivated (QSystemTrayIcon::ActivationReason reason);
107 void setTrayMessage (QString place, QString message); 108 void setTrayMessage (QString place, QString message);
108}; 109};
109 110
diff --git a/src/gnunet/gnunet.cpp b/src/gnunet/gnunet.cpp
index 73070d6..8886808 100644
--- a/src/gnunet/gnunet.cpp
+++ b/src/gnunet/gnunet.cpp
@@ -40,19 +40,10 @@ GnuNet::GnuNet (QObject * parent)
40 40
41GnuNet::~GnuNet () 41GnuNet::~GnuNet ()
42{ 42{
43 if (m_social) 43 qDebug () << "GnuNet: destructed";
44 {
45 delete m_social;
46 m_social = NULL;
47 }
48 setConnected (false);
49 GNUNET_SCHEDULER_shutdown ();
50} 44}
51 45
52 46
53/**
54 * Start GNUnet
55 */
56void 47void
57GnuNet::start () 48GnuNet::start ()
58{ 49{
@@ -63,10 +54,34 @@ GnuNet::start ()
63 GNUNET_PROGRAM_run (main_argc, main_argv, 54 GNUNET_PROGRAM_run (main_argc, main_argv,
64 APP_NAME, APP_NAME, 55 APP_NAME, APP_NAME,
65 options, mainLoopCallback, this); 56 options, mainLoopCallback, this);
57 qDebug () << "GnuNet: event loop finished";
66 Q_ASSERT (!m_connected); 58 Q_ASSERT (!m_connected);
67} 59}
68 60
69 61
62void
63GnuNet::stop ()
64{
65 emit shutdown ();
66}
67
68
69void
70GnuNet::shutdownSlot ()
71{
72 qDebug () << "GnuNet: shutting down";
73 if (m_social)
74 {
75 delete m_social;
76 m_social = NULL;
77 }
78 setConnected (false);
79 GNUNET_SCHEDULER_shutdown ();
80 qDebug () << "GnuNet: shut down finished";
81 emit stopped ();
82}
83
84
70/** 85/**
71 * The first function called when the GnuNet scheduler starts. 86 * The first function called when the GnuNet scheduler starts.
72 */ 87 */
@@ -78,6 +93,9 @@ GnuNet::mainLoop (char *const *args, const char *cfgfile,
78 Q_UNUSED (cfgfile); 93 Q_UNUSED (cfgfile);
79 Q_UNUSED (cfg); 94 Q_UNUSED (cfg);
80 95
96 connect (this, SIGNAL (shutdown ()),
97 this, SLOT (shutdownSlot ()), Qt::QueuedConnection);
98
81 // Create our configuration 99 // Create our configuration
82 m_config = GNUNET_CONFIGURATION_create (); 100 m_config = GNUNET_CONFIGURATION_create ();
83 GNUNET_CONFIGURATION_load (m_config, cfgfile); 101 GNUNET_CONFIGURATION_load (m_config, cfgfile);
@@ -95,21 +113,11 @@ GnuNet::mainLoop (char *const *args, const char *cfgfile,
95 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 113 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
96 shutdownTask, this); 114 shutdownTask, this);
97 115
98 // An update function to process our messages
99 GNUNET_SCHEDULER_add_now (processQtEventsTask, this);
100
101 connectServices ();
102}
103
104
105/**
106 * Connect to the services
107 */
108void
109GnuNet::connectServices ()
110{
111 m_social = new SocialApp (m_config, this); 116 m_social = new SocialApp (m_config, this);
112 setConnected (true); 117 setConnected (true);
118
119 // An update function to process our messages
120 GNUNET_SCHEDULER_add_now (processQtEventsTask, this);
113} 121}
114 122
115 123
@@ -143,9 +151,12 @@ GnuNet::processQtEventsTask (void *cls,
143 QCoreApplication::processEvents (); 151 QCoreApplication::processEvents ();
144 152
145 // Call again 153 // Call again
146 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 154 if (gnunet->isConnected ())
147 (GNUNET_TIME_UNIT_MILLISECONDS, 500), 155 {
148 processQtEventsTask, gnunet); 156 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
157 (GNUNET_TIME_UNIT_MILLISECONDS, 100),
158 processQtEventsTask, gnunet);
159 }
149} 160}
150 161
151 162
diff --git a/src/gnunet/gnunet.h b/src/gnunet/gnunet.h
index ae67ed1..0de079b 100644
--- a/src/gnunet/gnunet.h
+++ b/src/gnunet/gnunet.h
@@ -49,10 +49,30 @@ class GnuNet : public QObject
49 READ peerIdString 49 READ peerIdString
50 NOTIFY peerIdStringChanged); 50 NOTIFY peerIdStringChanged);
51 51
52 signals:
53
54 void shutdown ();
55 void stopped ();
56
57 void connectedChanged (bool connected);
58
59 void peerIdChanged (GNUNET_PeerIdentity peerId);
60
61 void peerIdStringChanged (QString peerIdStr);
62
63 public slots:
64
65 void start ();
66
67 private slots:
68
69 void shutdownSlot ();
70
52 public: 71 public:
53 72
54 explicit GnuNet (QObject *parent = 0); 73 explicit GnuNet (QObject *parent = 0);
55 ~GnuNet (); 74 ~GnuNet ();
75 void stop ();
56 76
57 SocialApp *social () const 77 SocialApp *social () const
58 { 78 {
@@ -85,6 +105,7 @@ class GnuNet : public QObject
85 return m_peerIdStr; 105 return m_peerIdStr;
86 } 106 }
87 107
108
88 private: 109 private:
89 110
90 GNUNET_PeerIdentity m_peerId; 111 GNUNET_PeerIdentity m_peerId;
@@ -107,25 +128,6 @@ class GnuNet : public QObject
107 shutdownTask (void *cls, 128 shutdownTask (void *cls,
108 const struct GNUNET_SCHEDULER_TaskContext *tc); 129 const struct GNUNET_SCHEDULER_TaskContext *tc);
109 130
110
111 signals:
112
113 void connectedChanged (bool connected);
114
115 void peerIdChanged (GNUNET_PeerIdentity peerId);
116
117 void peerIdStringChanged (QString peerIdStr);
118
119 public slots:
120
121 void start ();
122
123 private slots:
124
125 void connectServices ();
126
127 private:
128
129 SocialApp *m_social; 131 SocialApp *m_social;
130 132
131 struct GNUNET_CONFIGURATION_Handle *m_config; 133 struct GNUNET_CONFIGURATION_Handle *m_config;
diff --git a/src/main.cpp b/src/main.cpp
index 38d0993..986d12b 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -22,7 +22,6 @@ main (int argc, char **argv)
22 22
23 // connect window to quit signal 23 // connect window to quit signal
24 QObject *topLevel = engine.rootObjects ().value (0); 24 QObject *topLevel = engine.rootObjects ().value (0);
25
26 theWindow = qobject_cast < QQuickWindow * >(topLevel); 25 theWindow = qobject_cast < QQuickWindow * >(topLevel);
27 if (!theWindow) 26 if (!theWindow)
28 { 27 {
@@ -30,7 +29,9 @@ main (int argc, char **argv)
30 return -1; 29 return -1;
31 } 30 }
32 31
33 QObject::connect (&engine, SIGNAL (quit ()), &qapp, SLOT (quit ())); 32 QObject::connect (&engine, SIGNAL (quit ()),
33 &app, SLOT (close ()));
34
34 app.registerImageProvider (&engine); 35 app.registerImageProvider (&engine);
35 36
36 theWindow->setTitle (QString ("secushare 0.1")); 37 theWindow->setTitle (QString ("secushare 0.1"));
diff --git a/src/social/host.cpp b/src/social/host.cpp
index 86c112e..e76151b 100644
--- a/src/social/host.cpp
+++ b/src/social/host.cpp
@@ -1,10 +1,10 @@
1#include "host.h" 1#include "host.h"
2 2
3
4Host::Host (GNUNET_SOCIAL_App *app, 3Host::Host (GNUNET_SOCIAL_App *app,
5 GNUNET_SOCIAL_Ego *ego, 4 GNUNET_SOCIAL_Ego *ego,
6 enum GNUNET_PSYC_Policy policy, 5 enum GNUNET_PSYC_Policy policy,
7 QObject *parent) : Place (parent) 6 QObject *parent)
7 : Place (parent)
8{ 8{
9 m_app = app; 9 m_app = app;
10 m_ego = ego; 10 m_ego = ego;
@@ -23,7 +23,8 @@ Host::Host (GNUNET_SOCIAL_App *app,
23Host::Host (GNUNET_SOCIAL_App *app, 23Host::Host (GNUNET_SOCIAL_App *app,
24 GNUNET_SOCIAL_Ego *ego, 24 GNUNET_SOCIAL_Ego *ego,
25 GNUNET_SOCIAL_HostConnection *hconn, 25 GNUNET_SOCIAL_HostConnection *hconn,
26 QObject *parent) : Place (parent) 26 QObject *parent)
27 : Place (parent)
27{ 28{
28 m_app = app; 29 m_app = app;
29 m_ego = ego; 30 m_ego = ego;
@@ -64,7 +65,8 @@ Host::answerDoorCallback (void *cls, struct GNUNET_SOCIAL_Nym *nym,
64 "%s\n%.*s\n", method_name, data_size, data); 65 "%s\n%.*s\n", method_name, data_size, data);
65 66
66 Host *host = (Host *) cls; 67 Host *host = (Host *) cls;
67 emit host->answerDoorSignal (new Message (method_name, env, data, data_size, nym)); 68 emit host->answerDoorSignal (new Message (method_name, env, data, data_size,
69 nym, host));
68} 70}
69 71
70 72
diff --git a/src/social/host.h b/src/social/host.h
index d4aae3d..06ebc36 100644
--- a/src/social/host.h
+++ b/src/social/host.h
@@ -16,7 +16,7 @@ class Host : public Place
16 explicit 16 explicit
17 Host (GNUNET_SOCIAL_App *app, 17 Host (GNUNET_SOCIAL_App *app,
18 GNUNET_SOCIAL_Ego *ego, 18 GNUNET_SOCIAL_Ego *ego,
19 enum GNUNET_PSYC_Policy policy = GNUNET_PSYC_CHANNEL_PRIVATE, 19 enum GNUNET_PSYC_Policy policy,
20 QObject *parent = NULL); 20 QObject *parent = NULL);
21 21
22 explicit 22 explicit
diff --git a/src/social/place.cpp b/src/social/place.cpp
index 72c5693..28bf1a3 100644
--- a/src/social/place.cpp
+++ b/src/social/place.cpp
@@ -200,5 +200,9 @@ Place::notifyDataCallback (void *cls, uint16_t *data_size, void *data)
200 memcpy (data, sub.c_str (), *data_size); 200 memcpy (data, sub.c_str (), *data_size);
201 tmit->data_sent += *data_size; 201 tmit->data_sent += *data_size;
202 202
203 return (tmit->data.size () <= tmit->data_sent) ? GNUNET_YES : GNUNET_NO; 203 if (tmit->data_sent < tmit->data.size ())
204 return GNUNET_NO;
205
206 delete tmit;
207 return GNUNET_YES;
204} 208}
diff --git a/src/social/socialapp.cpp b/src/social/socialapp.cpp
index cd8f182..7ff6971 100644
--- a/src/social/socialapp.cpp
+++ b/src/social/socialapp.cpp
@@ -20,21 +20,16 @@ SocialApp::SocialApp (struct GNUNET_CONFIGURATION_Handle *config,
20 guestPlaceCallback, 20 guestPlaceCallback,
21 this); 21 this);
22 22
23 connect (this, &SocialApp::createPlaceSignal, this, 23 connect (this, &SocialApp::createPlaceSignal,
24 &SocialApp::createPlaceSlot, Qt::QueuedConnection); 24 this, &SocialApp::createPlaceSlot, Qt::QueuedConnection);
25 25
26 connect (this, &SocialApp::enterPlaceSignal, this, 26 connect (this, &SocialApp::enterPlaceSignal,
27 &SocialApp::enterPlaceSlot, Qt::QueuedConnection); 27 this, &SocialApp::enterPlaceSlot, Qt::QueuedConnection);
28} 28}
29 29
30 30
31SocialApp::~SocialApp () 31SocialApp::~SocialApp ()
32{ 32{
33 foreach (Place *place, m_places)
34 {
35 delete place;
36 }
37
38 GNUNET_SOCIAL_app_disconnect (m_app); 33 GNUNET_SOCIAL_app_disconnect (m_app);
39} 34}
40 35
@@ -61,7 +56,7 @@ SocialApp::hostPlaceCallback (void *cls,
61 enum GNUNET_SOCIAL_PlaceState placeState) 56 enum GNUNET_SOCIAL_PlaceState placeState)
62{ 57{
63 SocialApp *s = (SocialApp *) cls; 58 SocialApp *s = (SocialApp *) cls;
64 s->m_places += new Host (s->m_app, ego, hconn); 59 s->m_places += new Host (s->m_app, ego, hconn, s);
65} 60}
66 61
67 62
@@ -73,7 +68,7 @@ SocialApp::guestPlaceCallback (void *cls,
73 enum GNUNET_SOCIAL_PlaceState placeState) 68 enum GNUNET_SOCIAL_PlaceState placeState)
74{ 69{
75 SocialApp *s = (SocialApp *) cls; 70 SocialApp *s = (SocialApp *) cls;
76 s->m_places += new Guest (s->m_app, ego, gconn); 71 s->m_places += new Guest (s->m_app, ego, gconn, s);
77} 72}
78 73
79 74
@@ -82,7 +77,7 @@ SocialApp::placeCreate ()
82{ 77{
83 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Creating a New Place.\n"); 78 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Creating a New Place.\n");
84 79
85 Host *host = new Host (m_app, m_curEgo); // FIXME: ego 80 Host *host = new Host (m_app, m_curEgo, GNUNET_PSYC_CHANNEL_PRIVATE, this); // FIXME: ego
86 m_places += host; 81 m_places += host;
87} 82}
88 83
@@ -118,7 +113,7 @@ SocialApp::placeEnter (QString pubKeyStr, QString peerIdStr)
118 GNUNET_CRYPTO_eddsa_public_key_from_string (peerIdStr.toStdString ().c_str (), 113 GNUNET_CRYPTO_eddsa_public_key_from_string (peerIdStr.toStdString ().c_str (),
119 peerIdStr.length (), 114 peerIdStr.length (),
120 &peerId.public_key); 115 &peerId.public_key);
121 m_places += new Guest (m_app, m_curEgo, pubKey, &peerId); 116 m_places += new Guest (m_app, m_curEgo, pubKey, &peerId, 0, NULL, NULL, this);
122} 117}
123 118
124 119