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