cmake: no need to prepend prefix
[profile/ivi/automotive-message-broker.git] / ambd / core.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 CORE_H
21 #define CORE_H
22
23 #include "abstractsink.h"
24 #include "abstractsource.h"
25 #include "abstractroutingengine.h"
26 #include "asyncqueue.hpp"
27
28 #include <unordered_map>
29 #include <unordered_set>
30 #include <map>
31
32 class Core: public AbstractRoutingEngine
33 {
34
35 public:
36         Core(std::map<std::string, std::string> config);
37         ~Core();
38         /// sources:
39
40         void registerSource(AbstractSource *src);
41         void updateSupported(PropertyList added, PropertyList removed, AbstractSource* source);
42         void updateProperty(AbstractPropertyType* value, const std::string &uuid);
43
44         /// sinks:
45
46         void registerSink(AbstractSink *self);
47         void unregisterSink(AbstractSink *self);
48         AsyncPropertyReply* getPropertyAsync(AsyncPropertyRequest request);
49         void getRangePropertyAsync(AsyncRangePropertyRequest request);
50         AsyncPropertyReply * setProperty(AsyncSetPropertyRequest request);
51         uint subscribeToProperty(const VehicleProperty::Property &, AbstractRoutingEngine::PropertyChangedType, std::string pid="");
52         bool subscribeToProperty(const VehicleProperty::Property &, AbstractSink* self);
53         bool subscribeToProperty(const VehicleProperty::Property &, const std::string & sourceUuidFilter, AbstractSink *self);
54         bool subscribeToProperty(const VehicleProperty::Property &, const std::string & sourceUuidFilter, Zone::Type zoneFilter, AbstractSink *self);
55         bool unsubscribeToProperty(const VehicleProperty::Property &, AbstractSink* self);
56         void unsubscribeToProperty(uint handle);
57         PropertyList supported();
58
59         PropertyInfo getPropertyInfo(const VehicleProperty::Property &,const std::string &sourceUuid);
60         std::vector<std::string> sourcesForProperty(const VehicleProperty::Property & property);
61
62         struct Performance {
63                 Performance(): propertiesPerSecond(0), firedPropertiesPerSecond(0) {}
64                 int propertiesPerSecond;
65                 int firedPropertiesPerSecond;
66         };
67
68         void inspectSupported();
69
70 private:
71
72         void handleAddSupported(const PropertyList& added, AbstractSource* source);
73         void handleRemoveSupported(const PropertyList& removed, AbstractSource* source);
74         AbstractSource* sourceForProperty(const VehicleProperty::Property& property, const std::string& sourceUuidFilter = "") const;
75         void updateProperty(AbstractPropertyType* value);
76
77 private:
78
79         //typedef std::map< Zone::Type, AbstractPropertyType> ZonePropertyType;
80
81         // to support zone filtering replace VehicleProperty::Property with ZonePropertyType
82         std::multimap<AbstractSource*, VehicleProperty::Property> mMasterPropertyList;
83
84         std::unordered_set<AbstractSource*> mSources;
85         std::unordered_set<AbstractSink*> mSinks;
86
87         Performance performance;
88
89         // std::string here is AbstractSource::uuid()
90         typedef std::map<AbstractSink*, std::string> FilteredSourceSinkMap;
91
92         ///uint cbHandle, std::string uuid
93         typedef std::unordered_map<uint, std::string> FilteredSourceCbMap;
94
95         // to support zone filtering replace VehicleProperty::Property with ZonePropertyType
96         std::unordered_map<VehicleProperty::Property, FilteredSourceSinkMap > propertySinkMap;
97         std::unordered_map<VehicleProperty::Property, FilteredSourceCbMap> propertyCbMap;
98         std::unordered_map<uint, AbstractRoutingEngine::PropertyChangedType> handleCbMap;
99
100         amb::Queue<AbstractPropertyType*, amb::PropertyCompare> updatePropertyQueue;
101         amb::Queue<AbstractPropertyType*, amb::PropertyCompare> updatePropertyQueueHigh;
102         amb::Queue<AbstractPropertyType*, amb::PropertyCompare> updatePropertyQueueLow;
103         amb::AsyncQueueWatcher<AbstractPropertyType*, amb::PropertyCompare>* watcherPtr;
104         amb::AsyncQueueWatcher<AbstractPropertyType*, amb::PropertyCompare>* watcherPtrHigh;
105         amb::AsyncQueueWatcher<AbstractPropertyType*, amb::PropertyCompare>* watcherPtrLow;
106
107         uint handleCount;
108 };
109
110 #endif // CORE_H