Merge pull request #13 from timkoma/MasterPropertyList
[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 setSupported(PropertyList supported, AbstractSource* source);
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 private:
65
66         void handleAddSupported(const PropertyList& added, AbstractSource* source);
67         void handleRemoveSupported(const PropertyList& removed, AbstractSource* source);
68         AbstractSource* sourceForProperty(const VehicleProperty::Property& property, const std::string& sourceUuidFilter = "") const;
69
70 private:
71         
72         //typedef std::map< Zone::Type, AbstractPropertyType> ZonePropertyType;
73
74         // to support zone filtering replace VehicleProperty::Property with ZonePropertyType
75         std::multimap<AbstractSource*, VehicleProperty::Property> mMasterPropertyList;
76
77         // K = AbstractSource::uuid(), T = AbstractSource*
78         std::unordered_map<std::string, AbstractSource*> mSources;
79         std::set<AbstractSink*> mSinks;
80
81         Performance performance;
82         
83         // std::string here is AbstractSource::uuid()
84         typedef std::map<AbstractSink*, std::string> FilteredSourceSinkMap;
85
86         // to support zone filtering replace VehicleProperty::Property with ZonePropertyType
87         std::unordered_map<VehicleProperty::Property, FilteredSourceSinkMap > propertySinkMap;
88 };
89
90 #endif // CORE_H