1 //******************************************************************
3 // Copyright 2014 Intel Corporation All Rights Reserved.
4 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
9 // ============================================================================
11 // ============================================================================
17 #include "Protocol.hpp"
18 #include "UUIDLess.hpp"
19 #include "InternalApi.h"
23 // ============================================================================
25 // ============================================================================
30 class ModelImpl : public Model
33 typedef std::shared_ptr<ModelImpl> SharedPtr;
34 typedef std::weak_ptr<ModelImpl> WeakPtr;
38 static SharedPtr createModel();
41 // Constructor & Destructor
45 // Get the device list
46 virtual void getDevices(GetDevicesFunction& asyncReturnFunc);
48 // Add/remove device observer
49 virtual void removeDeviceObserver(DeviceObserverHandle observerHandle);
50 virtual void setDeviceObserver(DeviceEventFunction& asyncEventFunction);
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);
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;
64 const Protocols::Protocol::Handle generateProtocolHandle();
65 bool isHandleInUse(Protocols::Protocol::Handle handle);
66 Device::SharedPtr addDeviceToList(const UUID_t& deviceId);
68 DeviceObserverHandle generateDeviceObserverHandle();
69 bool isDeviceObserverHandleInUse(DeviceObserverHandle observerHandle);
70 DeviceIdList getDeviceIdList();
71 void notifyDeviceObservers(DeviceEvent::DeviceChange event, const DeviceIdList& deviceIdList);
74 ProtocolMap protocolMap_;
75 DeviceList deviceList_;
76 DeviceObserverMap deviceObserverMap_;
78 mutex protocolMapMutex_;
79 mutex deviceListMutex_;
80 mutex deviceObserverMapMutex_;
86 #endif /* MODELIMPL_H_ */