1 //******************************************************************
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
24 // ============================================================================
26 // ============================================================================
32 #include "Protocol.hpp"
33 #include "UUIDLess.hpp"
34 #include "InternalApi.h"
38 // ============================================================================
40 // ============================================================================
45 class ModelImpl : public Model
48 typedef std::shared_ptr<ModelImpl> SharedPtr;
49 typedef std::weak_ptr<ModelImpl> WeakPtr;
53 static SharedPtr createModel();
56 // Constructor & Destructor
60 // Get the device list
61 virtual void getDevices(GetDevicesFunction& asyncReturnFunc);
63 // Add/remove device observer
64 virtual void removeDeviceObserver(DeviceObserverHandle observerHandle);
65 virtual void setDeviceObserver(DeviceEventFunction& asyncEventFunction);
67 // Register/unregister a protocol
68 virtual const Protocols::Protocol::Handle registerProtocol(const Protocols::Protocol::SharedPtr& protocol);
69 virtual bool unregisterProtocol(const Protocols::Protocol::Handle protocolHandle);
70 virtual Device::SharedPtr getDevice(const UUID_t& deviceId);
71 virtual void signalDeviceChange(const UUID_t& deviceId, DeviceEvent::DeviceChange deviceEvent);
74 typedef std::map<Protocols::Protocol::Handle, Protocols::Protocol::WeakPtr> ProtocolMap;
75 typedef std::list<Device::SharedPtr> DeviceList;
76 typedef std::map<DeviceObserverHandle, DeviceEventFunction> DeviceObserverMap;
77 typedef std::list<UUID_t> DeviceIdList;
79 const Protocols::Protocol::Handle generateProtocolHandle();
80 bool isHandleInUse(Protocols::Protocol::Handle handle);
81 Device::SharedPtr addDeviceToList(const UUID_t& deviceId);
83 DeviceObserverHandle generateDeviceObserverHandle();
84 bool isDeviceObserverHandleInUse(DeviceObserverHandle observerHandle);
85 DeviceIdList getDeviceIdList();
86 void notifyDeviceObservers(DeviceEvent::DeviceChange event, const DeviceIdList& deviceIdList);
89 ProtocolMap protocolMap_;
90 DeviceList deviceList_;
91 DeviceObserverMap deviceObserverMap_;
93 mutex protocolMapMutex_;
94 mutex deviceListMutex_;
95 mutex deviceObserverMapMutex_;
101 #endif /* MODELIMPL_H_ */