a9fd240b5fe04e4d3a13c9187b423f03c32f6d90
[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 <QObject>
27 #include <QVariant>
28 #include <QJsonDocument>
29 #include <QDateTime>
30 #include <QScriptValue>
31 #include "uuidhelper.h"
32
33 #include "authenticate.h"
34 #include "agent.h"
35
36 class IrcCommunication;
37 class QScriptEngine;
38
39 class Property: public QObject, public AbstractSink
40 {
41         Q_OBJECT
42         Q_PROPERTY(QString type READ type)
43         Q_PROPERTY(QVariant value READ value WRITE setValue)
44
45 public:
46         Property(VehicleProperty::Property, QString srcFilter, AbstractRoutingEngine* re, QObject *parent = 0);
47
48         QString type();
49         void setType(QString t);
50
51         virtual PropertyList subscriptions() { return PropertyList(); }
52         virtual void supportedChanged(const PropertyList &)
53         {
54                 DebugOut()<<"Bluemonkey Property Supported Changed"<<endl;
55         }
56
57         virtual void propertyChanged(AbstractPropertyType* value);
58
59         virtual const std::string uuid() { return mUuid; }
60
61         QVariant value();
62         void setValue(QVariant v);
63
64         void getHistory(QDateTime begin, QDateTime end, QScriptValue cbFunction);
65 Q_SIGNALS:
66
67         void changed(QVariant val);
68
69 private:
70         AbstractPropertyType* mValue;
71         const std::string mUuid;
72
73 };
74
75 class BluemonkeySink : public QObject, public AmbPluginImpl
76 {
77 Q_OBJECT
78 public:
79         BluemonkeySink(AbstractRoutingEngine* e, map<string, string> config,  AbstractSource& parent);
80         virtual PropertyList subscriptions();
81         virtual void supportedChanged(const PropertyList & supportedProperties);
82         virtual void propertyChanged(AbstractPropertyType* value);
83         virtual const std::string uuid() const;
84
85         QScriptEngine* engine;
86
87         virtual int supportedOperations();
88
89 private: //source privates
90
91         PropertyList mSupported;
92         std::list<AbstractPropertyType*> propertyValueCache;
93
94
95 public Q_SLOTS:
96
97         QObject* subscribeTo(QString str);
98         QObject* subscribeTo(QString str, QString srcFilter);
99
100         QStringList sourcesForProperty(QString property);
101
102         QStringList supportedProperties();
103
104         bool authenticate(QString pass);
105
106         void loadConfig(QString str);
107
108         void reloadEngine();
109
110         void writeProgram(QString program);
111
112         void log(QString str);
113
114         void getHistory(QStringList properties, QDateTime begin, QDateTime end, QScriptValue cbFunction);
115
116         void setSilentMode(bool m)
117         {
118                 mSilentMode = m;
119         }
120
121         void createCustomProperty(QString name, QScriptValue defaultValue);
122
123 private:
124         QStringList configsToLoad;
125         IrcCommunication* irc;
126
127         Authenticate* auth;
128         BluemonkeyAgent* agent;
129         bool mSilentMode;
130 };
131
132
133 #endif // BluemonkeySink_H