some core changes as well as additions to opencv plugin
[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
27 #include <unordered_map>
28 #include <map>
29
30 class Core: public AbstractRoutingEngine
31 {
32         
33 public:
34         Core();
35         ~Core();
36         /// sources:
37
38         void registerSource(AbstractSource *src);
39         void updateSupported(PropertyList added, PropertyList removed, AbstractSource* source);
40         void updateProperty(AbstractPropertyType* value, const std::string &uuid);
41         
42         /// sinks:
43
44         void registerSink(AbstractSink *self);
45         void unregisterSink(AbstractSink *self);
46         AsyncPropertyReply* getPropertyAsync(AsyncPropertyRequest request);
47         AsyncRangePropertyReply* getRangePropertyAsync(AsyncRangePropertyRequest request);
48         AsyncPropertyReply * setProperty(AsyncSetPropertyRequest request);
49         bool subscribeToProperty(VehicleProperty::Property, AbstractSink* self);
50         bool subscribeToProperty(VehicleProperty::Property, std::string sourceUuidFilter, AbstractSink *self);
51         bool subscribeToProperty(VehicleProperty::Property, std::string sourceUuidFilter, Zone::Type zoneFilter, AbstractSink *self);
52         bool unsubscribeToProperty(VehicleProperty::Property, AbstractSink* self);
53         PropertyList supported();
54
55         PropertyInfo getPropertyInfo(VehicleProperty::Property, std::string sourceUuid);
56         std::list<std::string> sourcesForProperty(VehicleProperty::Property property);
57         
58         struct Performance {
59                 Performance(): propertiesPerSecond(0), firedPropertiesPerSecond(0) {}
60                 int propertiesPerSecond;
61                 int firedPropertiesPerSecond;
62         };
63
64         void inspectSupported();
65
66 private:
67
68         void handleAddSupported(const PropertyList& added, AbstractSource* source);
69         void handleRemoveSupported(const PropertyList& removed, AbstractSource* source);
70         AbstractSource* sourceForProperty(const VehicleProperty::Property& property, const std::string& sourceUuidFilter = "") const;
71
72 private:
73         
74         //typedef std::map< Zone::Type, AbstractPropertyType> ZonePropertyType;
75
76         // to support zone filtering replace VehicleProperty::Property with ZonePropertyType
77         std::multimap<AbstractSource*, VehicleProperty::Property> mMasterPropertyList;
78
79         // K = AbstractSource::uuid(), T = AbstractSource*
80         std::set<AbstractSource*> mSources;
81         std::set<AbstractSink*> mSinks;
82
83         Performance performance;
84         
85         // std::string here is AbstractSource::uuid()
86         typedef std::map<AbstractSink*, std::string> FilteredSourceSinkMap;
87
88         // to support zone filtering replace VehicleProperty::Property with ZonePropertyType
89         std::unordered_map<VehicleProperty::Property, FilteredSourceSinkMap > propertySinkMap;
90 };
91
92 #endif // CORE_H