19b8edbe8f1e568e3768efb1c5cd8de337201bfd
[profile/ivi/automotive-message-broker.git] / plugins / bluemonkey / bluemonkey.h
1 /*
2         Copyright (C) 2012  Intel Corporation
3
4         This library is free software; you can redistribute it and/or
5         modify it under the terms of the GNU Lesser General Public
6         License as published by the Free Software Foundation; either
7         version 2.1 of the License, or (at your option) any later version.
8
9         This library is distributed in the hope that it will be useful,
10         but WITHOUT ANY WARRANTY; without even the implied warranty of
11         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12         Lesser General Public License for more details.
13
14         You should have received a copy of the GNU Lesser General Public
15         License along with this library; if not, write to the Free Software
16         Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17 */
18
19
20 #ifndef BluemonkeySink_H
21 #define BluemonkeySink_H
22
23 #include "abstractsource.h"
24 #include "ambpluginimpl.h"
25
26 #include <map>
27
28 #include <QObject>
29 #include <QVariant>
30 #include <QJsonDocument>
31 #include <QDateTime>
32 #include <QJSValue>
33 #include "uuidhelper.h"
34
35 #include "authenticate.h"
36
37 class QJSEngine;
38
39 class ModuleInterface
40 {
41 public:
42         virtual std::map<std::string, QObject*> objects(std::map<string, string> config) = 0;
43 };
44
45 Q_DECLARE_INTERFACE(ModuleInterface, "org.automotive.bluemonkey.moduleinterface")
46
47 class Property: public QObject, public AbstractSink
48 {
49         Q_OBJECT
50         Q_PROPERTY(QString type READ type)
51         Q_PROPERTY(QVariant value READ value WRITE setValue)
52
53 public:
54         Property(VehicleProperty::Property, QString srcFilter, AbstractRoutingEngine* re, QObject *parent = 0);
55
56         QString type();
57         void setType(QString t);
58
59         virtual PropertyList subscriptions() { return PropertyList(); }
60         virtual void supportedChanged(const PropertyList &)
61         {
62                 DebugOut()<<"Bluemonkey Property Supported Changed"<<endl;
63         }
64
65         virtual void propertyChanged(AbstractPropertyType* value);
66
67         virtual const std::string uuid() { return mUuid; }
68
69         QVariant value();
70         void setValue(QVariant v);
71
72         void getHistory(QDateTime begin, QDateTime end, QJSValue cbFunction);
73 Q_SIGNALS:
74
75         void changed(QVariant val);
76
77 private:
78         AbstractPropertyType* mValue;
79         const std::string mUuid;
80
81 };
82
83 class BluemonkeySink : public QObject, public AmbPluginImpl
84 {
85 Q_OBJECT
86 public:
87         BluemonkeySink(AbstractRoutingEngine* e, map<string, string> config,  AbstractSource& parent);
88         virtual PropertyList subscriptions();
89         virtual void supportedChanged(const PropertyList & supportedProperties);
90         virtual void propertyChanged(AbstractPropertyType* value);
91         virtual const std::string uuid() const;
92
93         QJSEngine* engine;
94
95         virtual int supportedOperations();
96
97 private: //source privates
98
99         PropertyList mSupported;
100         std::list<AbstractPropertyType*> propertyValueCache;
101
102
103 public Q_SLOTS:
104
105         QObject* subscribeTo(QString str);
106         QObject* subscribeToSource(QString str, QString srcFilter);
107
108         QStringList sourcesForProperty(QString property);
109
110         QStringList supportedProperties();
111
112         bool authenticate(QString pass);
113
114         void loadConfig(QString str);
115
116         bool loadModule(QString path);
117
118         void reloadEngine();
119
120         void writeProgram(QString program);
121
122         void log(QString str);
123
124         QObject* createTimer();
125
126         void getHistory(QStringList properties, QDateTime begin, QDateTime end, QJSValue cbFunction);
127
128         void setSilentMode(bool m)
129         {
130                 mSilentMode = m;
131         }
132
133         void createCustomProperty(QString name, QJSValue defaultValue);
134
135 private:
136         QStringList configsToLoad;
137
138         Authenticate* auth;
139         bool mSilentMode;
140 };
141
142
143 #endif // BluemonkeySink_H