Added virtual destructors to CANSocketBCM and CANSocketRaw
[profile/ivi/automotive-message-broker.git] / xwalk / vehicle.h
1 // Copyright (c) 2014 Intel Corporation. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef VEHICLE_VEHICLE_H_
6 #define VEHICLE_VEHICLE_H_
7
8 #include <abstractpropertytype.h>
9 #include <gio/gio.h>
10 #include <glib.h>
11 #include <picojson.h>
12 #include <superptr.hpp>
13
14 #include <string>
15 #include <thread> // NOLINT
16 #include <vector>
17
18
19 namespace common {
20
21 class Instance;
22
23 }  // namespace common
24
25 struct ObjectZone {
26   ObjectZone():zone(0) {}
27
28   ObjectZone(const std::string& o, int z, const std::string& op)
29         : name(o), zone(z), object_path(op) {}
30
31   ObjectZone(const ObjectZone& other)
32         : name(other.name), zone(other.zone), object_path(other.object_path) {}
33
34   std::string name;
35   int zone;
36   uint handle;
37
38   std::string object_path;
39
40   bool operator ==(const ObjectZone& other) const {
41         return object_path == other.object_path;
42   }
43
44   picojson::object value;
45 };
46
47 struct ObjectZoneCompare {
48   bool operator() (const ObjectZone& lhs, const ObjectZone& rhs) {
49         return (lhs.name == rhs.name && lhs.zone < rhs.zone) ||
50                 (lhs.name < rhs.name);
51   }
52 };
53
54 typedef std::function<void (picojson::object)> GetReply;
55 typedef std::function<void (std::string)> ErrorReply;
56
57 class Vehicle {
58  public:
59   struct CallbackInfo {
60         std::string method;
61         static common::Instance* instance;
62         double callback_id;
63   };
64
65   explicit Vehicle(common::Instance* i);
66   ~Vehicle();
67
68   void Get(const std::string& property, Zone::Type zone, double ret_id);
69   void GetZones(const std::string& property, double ret_id);
70   void Subscribe(const std::string& property, Zone::Type zone);
71   void Unsubscribe(const std::string& property, Zone::Type zone);
72   void Set(const std::string& property, picojson::object value, Zone::Type zone, double ret_id);
73   void Supported(const std::string& property, double ret_id);
74   bool AvailableForRetrieval(const std::string& objectName, const std::string& attName);
75
76  private:
77   std::string FindProperty(const std::string& object_name, int zone, string &error_str);
78
79   static void SetupMainloop(void* data);
80   GMainLoop* main_loop_;
81   std::thread thread_;
82   common::Instance* instance_;
83
84   std::vector<ObjectZone*> amb_objects_;
85
86   amb::super_ptr<GDBusProxy> manager_proxy_;
87   amb::super_ptr<GDBusConnection> dbus_connection_;
88 };
89
90 #endif  // VEHICLE_VEHICLE_H_