summaryrefslogtreecommitdiff
path: root/main.cc
blob: 71d2b9fcbdae07aaae7c742859f0427fc16d2c92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include <QtCore/QCoreApplication>
#include <QtCore/QSettings>
#include <QtCore/QStringList>
#include "sapmanager.h"
#include "sapbtlistener.h"

#include "capabilityagent.h"
#include "hostmanageragent.h"
#include "webproxyagent.h"
#include "notificationagent.h"

using std::cerr;
using std::endl;

int main(int argc, char *argv[])
{
	QCoreApplication app(argc, argv);
	app.setOrganizationName("javispedro");
	app.setOrganizationDomain("com.javispedro");
	app.setApplicationName("sapd");

	QBluetoothAddress address;
	QSettings settings;
	QString address_from_settings = settings.value("device/address").toString();
	if (!address_from_settings.isEmpty()) {
		address = QBluetoothAddress(address_from_settings);
	}

	if (app.arguments().size() >= 2) {
		// Get the address from the command line.
		address = QBluetoothAddress(app.arguments().at(1));
	}

	if (address.isNull()) {
		cerr << "Usage: sapd <bt address>" << endl;
		cerr << "If you don't want to specify the BT address every time, put it in "
			 << qPrintable(settings.fileName())
			 << endl;
		settings.setValue("device/address", QString());
		return EXIT_FAILURE;
	}

	SAPManager *manager = SAPManager::instance();

	CapabilityAgent::registerServices(manager);
	HostManagerAgent::registerServices(manager);
	WebProxyAgent::registerServices(manager);
	NotificationAgent::registerServices(manager);

	QScopedPointer<SAPBTListener> sap_listener(new SAPBTListener);

	sap_listener->start();
	sap_listener->nudge(address);

	return app.exec();
}