summaryrefslogtreecommitdiff
path: root/plugins/bluemonkey/bluemonkey.h
blob: 13c7c3093eb0c2e47f829fee275eba4ee46123f8 (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*
	Copyright (C) 2012  Intel Corporation

	This library is free software; you can redistribute it and/or
	modify it under the terms of the GNU Lesser General Public
	License as published by the Free Software Foundation; either
	version 2.1 of the License, or (at your option) any later version.

	This library is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
	Lesser General Public License for more details.

	You should have received a copy of the GNU Lesser General Public
	License along with this library; if not, write to the Free Software
	Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/


#ifndef BluemonkeySink_H
#define BluemonkeySink_H

#include "abstractsource.h"
#include "ambpluginimpl.h"

#include <map>

#include <QObject>
#include <QVariant>
#include <QJsonDocument>
#include <QDateTime>
#include <QJSValue>
#include "uuidhelper.h"

#include "authenticate.h"

class QJSEngine;

class ModuleInterface
{
public:
	virtual std::map<std::string, QObject*> objects(std::map<string, string> config) = 0;
};

Q_DECLARE_INTERFACE(ModuleInterface, "org.automotive.bluemonkey.moduleinterface")

class Property: public QObject, public AbstractSink
{
	Q_OBJECT
	Q_PROPERTY(QString name READ name)
	Q_PROPERTY(QString source READ source)
	Q_PROPERTY(double timestamp READ timestamp)
	Q_PROPERTY(QVariant value READ value WRITE setValue)
	Q_PROPERTY(int zone READ zone)

public:
	Property(VehicleProperty::Property, QString srcFilter, AbstractRoutingEngine* re, Zone::Type zone = Zone::None, QObject *parent = 0);

	QString name();
	void setType(QString t);

	QString source()
	{
		return mValue->sourceUuid.c_str();
	}

	double timestamp()
	{
		return mValue->timestamp;
	}

	virtual PropertyList subscriptions() { return PropertyList(); }
	virtual void supportedChanged(const PropertyList &)
	{
		DebugOut()<<"Bluemonkey Property Supported Changed"<<endl;
	}

	virtual void propertyChanged(AbstractPropertyType* value);

	virtual const std::string uuid() { return mUuid; }

	QVariant value();
	void setValue(QVariant v);

	void getHistory(QDateTime begin, QDateTime end, QJSValue cbFunction);

	Zone::Type zone() { return mZone; }

Q_SIGNALS:

	void changed(QVariant val);

private:
	AbstractPropertyType* mValue;
	const std::string mUuid;
	Zone::Type mZone;

};

class BluemonkeySink : public QObject, public AmbPluginImpl
{
Q_OBJECT

public:
	using AmbPluginImpl::setProperty;
	using QObject::setProperty;

	BluemonkeySink(AbstractRoutingEngine* e, map<string, string> config,  AbstractSource& parent);
	~BluemonkeySink();
	virtual PropertyList subscriptions();
	virtual void supportedChanged(const PropertyList & supportedProperties);
	virtual void propertyChanged(AbstractPropertyType* value);
	virtual const std::string uuid() const;

	virtual int supportedOperations();

private: //source privates

	PropertyList mSupported;
	std::list<AbstractPropertyType*> propertyValueCache;


public Q_SLOTS:

	QObject* subscribeTo(QString str);
	QObject* subscribeTo(QString str, int zone);
	QObject* subscribeTo(QString str, int zone, QString srcFilter);

	QStringList sourcesForProperty(QString property);
	QVariant zonesForProperty(QString property, QString src);

	QStringList supportedProperties();

	bool authenticate(QString pass);

	void loadConfig(QString str);

	bool loadModule(QString path);

	void reloadEngine();

	void writeProgram(QString program);

	void log(QString str);

	QObject* createTimer();
	QObject* createQObject();

	void getHistory(QStringList properties, QDateTime begin, QDateTime end, QJSValue cbFunction);

	void setSilentMode(bool m)
	{
		mSilentMode = m;
	}

	void createCustomProperty(QString name, QJSValue defaultValue)
	{
		createCustomProperty(name, defaultValue, Zone::None);
	}

	void createCustomProperty(QString name, QJSValue defaultValue, int zone);

	void exportInterface(QString name, QJSValue properties);

private:
	QList<void*> modules;
	QJSEngine* engine;
	QStringList configsToLoad;

	Authenticate* auth;
	bool mSilentMode;
};


#endif // BluemonkeySink_H