Skip to content

Commit 78e9c3f

Browse files
committed
first commit
0 parents  commit 78e9c3f

20 files changed

+3681
-0
lines changed

cmst.pro

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# We need the qt libraries, we want compiler warnings off, and this is a release version of the program
2+
CONFIG += qt warn_off release
3+
#CONFIG += qt warn_on release
4+
5+
# Widgets needed for QT5,
6+
QT += widgets
7+
QT += dbus
8+
9+
# dbus
10+
DBUS_ADAPTORS += ./code/agent/org.monkey_business_enterprises.agent.xml
11+
DBUS_INTERFACES += ./code/agent/org.monkey_business_enterprises.agent.xml
12+
DBUS_ADAPTORS += ./code/counter/org.monkey_business_enterprises.counter.xml
13+
DBUS_INTERFACES += ./code/counter/org.monkey_business_enterprises.counter.xml
14+
15+
# header files
16+
HEADERS += ./code/resource.h
17+
HEADERS += ./code/control_box/controlbox.h
18+
HEADERS += ./code/agent/agent.h
19+
HEADERS += ./code/agent/agent_dialog.h
20+
HEADERS += ./code/counter/counter.h
21+
22+
# forms
23+
FORMS += ./code/control_box/ui/controlbox.ui
24+
FORMS += ./code/agent/ui/agent.ui
25+
26+
# sources
27+
SOURCES += ./code/main.cpp
28+
SOURCES += ./code/control_box/controlbox.cpp
29+
SOURCES += ./code/agent/agent.cpp
30+
SOURCES += ./code/agent/agent_dialog.cpp
31+
SOURCES += ./code/counter/counter.cpp
32+
33+
# resource files
34+
RESOURCES += cmst.qrc
35+
36+
# following 4 lines if we want the source the QT dynamic libraries
37+
# with our exec file (or exepath/lib or exepath/libs)
38+
#QMAKE_LFLAGS += -Wl,-rpath=\\\$\$ORIGIN
39+
#QMAKE_LFLAGS += -Wl,-rpath=\\\$\$ORIGIN/lib
40+
#QMAKE_LFLAGS += -Wl,-rpath=\\\$\$ORIGIN/libs
41+
#QMAKE_RPATH=
42+
43+
## Place all object files in their own directory and moc files in their own directory
44+
## This is not necessary but keeps things cleaner.
45+
OBJECTS_DIR = ./object_files
46+
MOC_DIR = ./moc_files
47+
48+
49+
sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro
50+

cmst.qrc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<RCC>
2+
<qresource prefix="text">
3+
<file>text/changelog.txt</file>
4+
<file>text/license.txt</file>
5+
</qresource>
6+
<qresource prefix="icons16x16">
7+
<file>images/16x16/help.png</file>
8+
<file>images/16x16/connect_established.png</file>
9+
<file>images/16x16/bookmark.png</file>
10+
<file>images/16x16/ledgreen.png</file>
11+
<file>images/16x16/ledred.png</file>
12+
<file>images/16x16/connect_creating.png</file>
13+
<file>images/16x16/connect_no.png</file>
14+
<file>images/16x16/cancel.png</file>
15+
</qresource>
16+
</RCC>

code/agent/agent.cpp

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
/**************************** agent.cpp ********************************
2+
3+
Code for the user agent registered on DBus. When the connman daemon
4+
needs to communicate with the user it does so through this agent.
5+
6+
Copyright (C) 2013-2014
7+
by: Andrew J. Bibb
8+
License: MIT
9+
10+
Permission is hereby granted, free of charge, to any person obtaining a copy
11+
of this software and associated documentation files (the "Software"),to deal
12+
in the Software without restriction, including without limitation the rights
13+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+
copies of the Software, and to permit persons to whom the Software is
15+
furnished to do so, subject to the following conditions:
16+
17+
The above copyright notice and this permission notice shall be included
18+
in all copies or substantial portions of the Software.
19+
20+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26+
DEALINGS IN THE SOFTWARE.
27+
***********************************************************************/
28+
29+
# include <QtCore/QDebug>
30+
# include <QtDBus/QDBusConnection>
31+
# include <QMessageBox>
32+
# include <QDialog>
33+
# include <QFile>
34+
# include <QTextStream>
35+
36+
# include "./code/agent/agent.h"
37+
# include "./code/resource.h"
38+
39+
// header files generated by qmake from the xml file created by qdbuscpp2xml
40+
# include "agent_adaptor.h"
41+
# include "agent_interface.h"
42+
43+
// defines
44+
# define ERROR_RETRY "net.connman.Agent.Error.Retry"
45+
# define ERROR_CANCELED "net.connman.Agent.Error.Canceled"
46+
# define ERROR_LAUNCHBROWSER "net.connman.Agent.Error.LaunchBrowser"
47+
48+
// constructor
49+
ConnmanAgent::ConnmanAgent(QObject* parent)
50+
: QObject(parent)
51+
{
52+
// members
53+
uiDialog = new AgentDialog(qobject_cast<QWidget *> (this) );
54+
input_map.clear();
55+
b_loginputrequest = false;
56+
57+
// Create Adaptor and register this Agent on the system bus.
58+
new AgentAdaptor(this);
59+
QDBusConnection::systemBus().registerObject("/org/monkeybusiness/Agent", this);
60+
61+
// Create an Interface for the Agent
62+
net::connman::Agent* iface;
63+
iface = new net::connman::Agent(QString("net.connman.Agent"), QString("/org/monkeybusiness/Agent"), QDBusConnection::systemBus(), this);
64+
}
65+
66+
/////////////////////////////////////// PUBLIC Q_SLOTS////////////////////////////////
67+
//
68+
// Called when the service daemon unregisters the agent. QT deals with cleanup
69+
// tasks so don't need much here
70+
void ConnmanAgent::Release()
71+
{
72+
return;
73+
}
74+
75+
// Called when an error has to be reported to the user. Show the
76+
// error in a QMessageBox
77+
void ConnmanAgent::ReportError(QDBusObjectPath path, QString s_error)
78+
{
79+
if ( QMessageBox::warning(qobject_cast<QWidget *> (parent()), tr("Connman Error"),
80+
tr("Connman returned the following error:<b><center>%1</b><br>Would you like to retry?").arg(s_error),
81+
QMessageBox::Yes | QMessageBox::No,
82+
QMessageBox::No
83+
) == QMessageBox::Yes) this->sendErrorReply(ERROR_RETRY, "Going to retry the request");
84+
85+
else return;
86+
}
87+
88+
//ff
89+
// Called when it is required to ask the user to open qa website to proceed
90+
// with login handling
91+
void ConnmanAgent::RequestBrowser(QDBusObjectPath path, QString url)
92+
{
93+
// Send the url to the dialog to have the user the necessary information, return if canceled.
94+
if (this->uiDialog->showPage1(url) == QDialog::Rejected) this->sendErrorReply(ERROR_CANCELED,"User cancelled the dialog");
95+
96+
return;
97+
}
98+
99+
//
100+
// Called when trying to connect to a service and some extra input is required from the user
101+
// A dialog is displayed with the required fields enabled (non-required fields are disabled).
102+
QVariantMap ConnmanAgent::RequestInput(QDBusObjectPath path, QMap<QString,QVariant> dict)
103+
{
104+
// Take the dict returned by DBus and extract the information we are interested in and place in input_map.
105+
this->createInputMap(dict);
106+
107+
// Send our input_map to the dialog to have the user supply the necessary information
108+
// needed to continue. Return if canceled.
109+
if (this->uiDialog->showPage0(input_map) == QDialog::Rejected) this->sendErrorReply(ERROR_CANCELED,"User cancelled the dialog");
110+
111+
// Create a return dict and send it back to connman on DBus
112+
QMap<QString,QVariant> rtn;
113+
rtn.clear();
114+
uiDialog->createDict(rtn);
115+
return rtn;
116+
}
117+
118+
//
119+
// Called when the agent request failed before a reply was returned. Show
120+
// a QMessageBox
121+
void ConnmanAgent::Cancel()
122+
{
123+
QMessageBox::information(qobject_cast<QWidget *> (parent()), tr("Agent Request Failed"),
124+
tr("The agent request failed before a reply was returned.") );
125+
126+
return;
127+
}
128+
129+
/////////////////////////////////////// PUBLIC FUNCTIONS ////////////////////////////////
130+
//
131+
// Function to put all of input fields received via DBus:RequestInput into a
132+
// QMap<QString,QString> where key is the input field received and value is
133+
// generally blank but can be used for informational text.
134+
//
135+
// If we asked to log the input request create the log file in /tmp/cmst/input_request.log
136+
137+
void ConnmanAgent::createInputMap(const QMap<QString,QVariant>& r_map)
138+
{
139+
// Initialize our data map
140+
input_map.clear();
141+
142+
// QFile object for logging
143+
QTextStream log;
144+
QFile logfile("/tmp/cmst/input_request.log");
145+
if (b_loginputrequest) {
146+
QDir d;
147+
d.mkpath("/tmp/cmst");
148+
if (logfile.exists()) logfile.remove();
149+
if (!logfile.open(QIODevice::WriteOnly | QIODevice::Text)) b_loginputrequest = false;
150+
else log.setDevice(&logfile);
151+
}
152+
153+
154+
// Run through the r_map getting the keys and the few values we are interested in.
155+
QMap<QString, QVariant>::const_iterator i = r_map.constBegin();
156+
while (i != r_map.constEnd()) {
157+
158+
// Lets see what the values contain, but first make sure we can get to them.
159+
if (b_loginputrequest) log << "\nMap Key: " << i.key() << "\n";
160+
161+
if (! i.value().canConvert<QDBusArgument>() ) return;
162+
const QDBusArgument qdba = i.value().value<QDBusArgument>();
163+
if ( ! qdba.currentType() == QDBusArgument::MapType ) {
164+
if (b_loginputrequest) log << "Error - QDBusArgument as the value is not a MapType\n";
165+
return;
166+
}
167+
168+
// The r_map.value() is a QDBusArgument::MapType so extract this map into a new QMap called m.
169+
qdba.beginMap();
170+
QMap<QString,QString> m;
171+
m.clear();
172+
if (b_loginputrequest) log << "Extracting the DBusArgument Map...\n";
173+
while ( ! qdba.atEnd() ) {
174+
QString k;
175+
QVariant v;
176+
qdba.beginMapEntry();
177+
qdba >> k >> v;
178+
qdba.endMapEntry();
179+
m.insert(k, v.toString());
180+
if (b_loginputrequest) log << "{ " << k << " , " << v.toString() << "}\n";
181+
} // while
182+
qdba.endMap();
183+
184+
// Browse through QMap m and get things we need to look at
185+
// Types we don' really care about. We ignore "optional" and "alternate" requirements
186+
// and only extract the "mandatory" and "informational" requirements with values
187+
if (m.contains("Requirement") ) {
188+
QString val = QString();
189+
if ( m.value("Requirement").contains("mandatory", Qt::CaseInsensitive) || m.value("Requirement").contains("informational", Qt::CaseInsensitive) ) {
190+
if (m.contains("Value") ) val = m.value("Value");
191+
} // if mandatory or informational
192+
// create our input_map entry
193+
input_map[i.key()] = val;
194+
} // if requirement
195+
196+
++i;
197+
} // while
198+
199+
logfile.close();
200+
return;
201+
}
202+

code/agent/agent.h

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**************************** agent.h **********************************
2+
3+
Code for the user agent registered on DBus. When the connman daemon
4+
needs to communicate with the user it does so through this agent.
5+
6+
Copyright (C) 2013-2014
7+
by: Andrew J. Bibb
8+
License: MIT
9+
10+
Permission is hereby granted, free of charge, to any person obtaining a copy
11+
of this software and associated documentation files (the "Software"),to deal
12+
in the Software without restriction, including without limitation the rights
13+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+
copies of the Software, and to permit persons to whom the Software is
15+
furnished to do so, subject to the following conditions:
16+
17+
The above copyright notice and this permission notice shall be included
18+
in all copies or substantial portions of the Software.
19+
20+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26+
DEALINGS IN THE SOFTWARE.
27+
***********************************************************************/
28+
29+
30+
# ifndef CONNMANAGENT
31+
# define CONNMANAGENT
32+
33+
# include <QObject>
34+
# include <QString>
35+
# include <QMap>
36+
# include <QVariant>
37+
# include <QVariantMap>
38+
# include <QtDBus/QDBusObjectPath>
39+
# include <QtDBus/QDBusContext>
40+
41+
# include "./code/agent/agent_dialog.h"
42+
43+
class ConnmanAgent : public QObject, protected QDBusContext
44+
{
45+
Q_OBJECT
46+
Q_CLASSINFO("D-Bus Interface", "net.connman.Agent")
47+
48+
public:
49+
ConnmanAgent(QObject*);
50+
51+
inline void setLogInputRequest(bool b) {b_loginputrequest = b;}
52+
53+
public Q_SLOTS:
54+
void Release();
55+
void ReportError(QDBusObjectPath, QString);
56+
void RequestBrowser(QDBusObjectPath, QString);
57+
QVariantMap RequestInput(QDBusObjectPath, QMap<QString,QVariant>);
58+
void Cancel();
59+
60+
private:
61+
AgentDialog* uiDialog;
62+
QMap<QString,QString> input_map;
63+
bool b_loginputrequest;
64+
65+
void createInputMap(const QMap<QString,QVariant>&);
66+
};
67+
68+
#endif

0 commit comments

Comments
 (0)