Initial merge-commit of the OIC code. Should successfully do discovery for single...
[platform/upstream/iotivity.git] / csdk / controller / core / src / ModelImpl.h
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Corporation All Rights Reserved.
4 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
5
6 #ifndef MODELIMPL_H_
7 #define MODELIMPL_H_
8
9 // ============================================================================
10 // Includes
11 // ============================================================================
12 #include <memory>
13 #include <map>
14 #include <list>
15 #include <stdint.h>
16
17 #include "Protocol.hpp"
18 #include "UUIDLess.hpp"
19 #include "InternalApi.h"
20 #include "Core.h"
21
22
23 // ============================================================================
24 // Namespace
25 // ============================================================================
26 namespace Intel {
27 namespace CCFL {
28 namespace API {
29
30 class ModelImpl : public Model
31 {
32 public:
33         typedef std::shared_ptr<ModelImpl> SharedPtr;
34         typedef std::weak_ptr<ModelImpl> WeakPtr;
35
36 public:
37         // Factory
38         static SharedPtr createModel();
39
40 public:
41         // Constructor & Destructor
42         ModelImpl();
43         virtual ~ModelImpl();
44
45         // Get the device list
46         virtual void getDevices(GetDevicesFunction& asyncReturnFunc);
47
48         // Add/remove device observer
49         virtual void removeDeviceObserver(DeviceObserverHandle observerHandle);
50         virtual void setDeviceObserver(DeviceEventFunction& asyncEventFunction);
51
52         // Register/unregister a protocol
53         virtual const Protocols::Protocol::Handle registerProtocol(const Protocols::Protocol::SharedPtr& protocol);
54         virtual bool unregisterProtocol(const Protocols::Protocol::Handle protocolHandle);
55         virtual Device::SharedPtr getDevice(const UUID_t& deviceId);
56         virtual void signalDeviceChange(const UUID_t& deviceId, DeviceEvent::DeviceChange deviceEvent);
57
58 private:
59         typedef std::map<Protocols::Protocol::Handle, Protocols::Protocol::WeakPtr> ProtocolMap;
60         typedef std::list<Device::SharedPtr> DeviceList;
61         typedef std::map<DeviceObserverHandle, DeviceEventFunction> DeviceObserverMap;
62         typedef std::list<UUID_t> DeviceIdList;
63 private:
64         const Protocols::Protocol::Handle generateProtocolHandle();
65         bool isHandleInUse(Protocols::Protocol::Handle handle);
66         Device::SharedPtr addDeviceToList(const UUID_t& deviceId);
67
68         DeviceObserverHandle generateDeviceObserverHandle();
69   bool isDeviceObserverHandleInUse(DeviceObserverHandle observerHandle);
70   DeviceIdList getDeviceIdList();
71   void notifyDeviceObservers(DeviceEvent::DeviceChange event, const DeviceIdList& deviceIdList);
72
73 private:
74         ProtocolMap protocolMap_;
75         DeviceList deviceList_;
76         DeviceObserverMap deviceObserverMap_;
77
78         mutex protocolMapMutex_;
79         mutex deviceListMutex_;
80         mutex deviceObserverMapMutex_;
81 };
82
83 }
84 }
85 }
86 #endif /* MODELIMPL_H_ */