34 #include "../DeviceDescription/HomegearDevice.h" 35 #include "../Database/DatabaseTypes.h" 36 #include "../Sockets/RpcClientInfo.h" 37 #include "../ScriptEngine/ScriptInfo.h" 39 #include "../DeviceDescription/DeviceTranslations.h" 43 #include <unordered_map> 52 class IWebserverEventSink;
64 uint64_t databaseId = 0;
69 int32_t specialType = 0;
89 void unlock() noexcept;
95 std::vector<uint8_t>::size_type getBinaryDataSize() noexcept;
101 std::vector<uint8_t> getBinaryData() noexcept;
107 std::vector<uint8_t> &getBinaryDataReference() noexcept;
113 void setBinaryData(std::vector<uint8_t> &
value) noexcept;
119 std::vector<uint8_t> getPartialBinaryData() noexcept;
125 std::vector<uint8_t> &getPartialBinaryDataReference() noexcept;
131 void setPartialBinaryData(std::vector<uint8_t> &value) noexcept;
143 void setLogicalData(
PVariable value) noexcept;
149 bool equals(std::vector<uint8_t> &value) noexcept;
152 std::lock_guard<std::mutex> categoriesGuard(_categoriesMutex);
153 return _categories.find(
id) != _categories.end();
156 std::lock_guard<std::mutex> categoriesGuard(_categoriesMutex);
157 _categories.emplace(
id);
160 std::lock_guard<std::mutex> categoriesGuard(_categoriesMutex);
161 _categories.erase(
id);
164 std::lock_guard<std::mutex> categoriesGuard(_categoriesMutex);
167 std::string getCategoryString();
169 std::lock_guard<std::mutex> categoriesGuard(_categoriesMutex);
170 return !_categories.empty();
174 std::lock_guard<std::mutex> rolesGuard(_rolesMutex);
175 return _roles.find(
id) != _roles.end();
178 std::lock_guard<std::mutex> rolesGuard(_rolesMutex);
179 for (
auto &
role: _roles) {
181 if (((hexRole & 0xFF0000)) == 0x800000)
return true;
187 void removeRole(uint64_t
id);
189 std::lock_guard<std::mutex> rolesGuard(_rolesMutex);
190 auto rolesIterator = _roles.find(
id);
191 if (rolesIterator != _roles.end())
return rolesIterator->second;
else return Role();
194 std::lock_guard<std::mutex> rolesGuard(_rolesMutex);
197 std::string getRoleString();
199 std::lock_guard<std::mutex> rolesGuard(_rolesMutex);
200 return !_roles.empty();
214 return _buildingPart;
220 std::mutex _logicalDataMutex;
222 std::mutex _binaryDataMutex;
223 std::vector<uint8_t> _binaryData;
224 std::vector<uint8_t> _partialBinaryData;
225 std::mutex _categoriesMutex;
226 std::set<uint64_t> _categories;
227 std::mutex _rolesMutex;
232 bool _invert =
false;
235 std::unordered_map<uint64_t, Role> _roles;
236 std::atomic<uint64_t> _room{0};
237 std::atomic<uint64_t> _buildingPart{0};
250 void lock() noexcept;
255 void unlock() noexcept;
261 std::vector<uint8_t>::size_type getBinaryDataSize() noexcept;
267 std::vector<uint8_t> getBinaryData() noexcept;
273 std::vector<uint8_t> &getBinaryDataReference() noexcept;
279 void setBinaryData(std::vector<uint8_t> &
value) noexcept;
285 bool equals(std::vector<uint8_t> &value) noexcept;
290 uint64_t databaseId = 0;
292 std::mutex _binaryDataMutex;
293 std::vector<uint8_t> _binaryData;
299 BasicPeer(int32_t address, std::string serial,
bool isVirtual) {
300 this->address = address;
301 serialNumber = serial;
302 this->isVirtual = isVirtual;
307 bool hasSender =
false;
308 bool isSender =
false;
313 int32_t physicalIndexOffset = 0;
314 bool isVirtual =
false;
318 int32_t configEEPROMAddress = -1;
328 virtual void onRemoveWebserverEventHandler(std::map<int32_t, PEventHandler> &eventHandlers) = 0;
330 virtual void onRPCEvent(std::string &source, uint64_t
id, int32_t
channel, std::string &deviceAddress, std::shared_ptr<std::vector<std::string>> &valueKeys, std::shared_ptr<std::vector<PVariable>> &values) = 0;
331 virtual void onRPCUpdateDevice(uint64_t
id, int32_t channel, std::string address, int32_t hint) = 0;
332 virtual void onEvent(std::string &source, uint64_t peerID, int32_t channel, std::shared_ptr<std::vector<std::string>> &variables, std::shared_ptr<std::vector<PVariable>> &values) = 0;
333 virtual void onServiceMessageEvent(
const PServiceMessage &serviceMessage) = 0;
339 static const uint64_t kMaximumPeerId = 0x3FFFFFFF;
340 static constexpr std::pair<uint64_t, uint64_t> kVirtualPeerIdRange{0x40000000, 0x4FFFFFFF};
341 static constexpr std::pair<uint64_t, uint64_t> kUiPeerIdRange{0x50000000, 0x5FFFFFFF};
347 initializeTypeString();
352 std::unordered_map<uint32_t, std::unordered_map<std::string, RpcConfigurationParameter>>
configCentral;
353 std::unordered_map<uint32_t, std::unordered_map<std::string, RpcConfigurationParameter>>
valuesCentral;
354 std::unordered_map<uint32_t, std::unordered_map<int32_t, std::unordered_map<uint32_t, std::unordered_map<std::string, RpcConfigurationParameter>>>>
linksCentral;
360 virtual void dispose();
363 virtual bool wireless() = 0;
369 virtual uint64_t
getID() {
return _peerID; }
370 virtual void setID(uint64_t
id);
373 if (_peerID > 0) save(
true,
false,
false);
376 virtual void setSerialNumber(std::string serialNumber);
382 _firmwareVersion =
value;
383 saveVariable(1001, value);
387 _firmwareVersionString =
value;
388 saveVariable(1003, value);
393 saveVariable(1002, (int64_t)_deviceType);
394 initializeTypeString();
397 virtual std::string getName(int32_t
channel);
399 virtual void setName(int32_t channel, std::string
value);
400 virtual std::string
getIp() {
return _ip; }
401 virtual void setIp(std::string value) {
403 saveVariable(1004, value);
408 saveVariable(1005, value);
413 saveVariable(1006, value);
415 virtual std::set<int32_t> getChannelsInRoom(uint64_t roomId);
416 virtual uint64_t getRoom(int32_t channel);
417 virtual bool hasRoomInChannels(uint64_t roomId);
419 virtual bool setRoom(int32_t channel, uint64_t value);
420 virtual std::set<int32_t> getChannelsInBuildingPart(uint64_t buildingPartId);
421 virtual uint64_t getBuildingPart(int32_t channel);
422 virtual bool hasBuildingPartInChannels(uint64_t buildingPartId);
423 bool buildingPartsSet();
424 virtual bool setBuildingPart(int32_t channel, uint64_t value);
425 virtual std::unordered_map<int32_t, std::set<uint64_t>> getCategories();
426 virtual std::set<uint64_t> getCategories(int32_t channel);
427 virtual std::set<int32_t> getChannelsInCategory(uint64_t categoryId);
428 virtual bool hasCategories();
429 virtual bool hasCategories(int32_t channel);
430 virtual bool hasCategory(int32_t channel, uint64_t
id);
431 virtual bool hasCategoryInChannels(uint64_t categoryId);
432 virtual bool addCategory(int32_t channel, uint64_t
id);
433 virtual bool removeCategory(int32_t channel, uint64_t
id);
438 virtual std::string handleCliCommand(std::string command) = 0;
441 virtual void setLastPacketReceived();
445 virtual int32_t getChannelGroupedWith(int32_t channel) = 0;
446 virtual int32_t getNewFirmwareVersion() = 0;
447 virtual std::string getFirmwareVersionString(int32_t firmwareVersion) = 0;
448 virtual bool firmwareUpdateAvailable() = 0;
450 virtual bool setVariableRoom(int32_t channel, std::string &variableName, uint64_t roomId);
451 virtual void removeRoomFromVariables(uint64_t roomId);
452 virtual uint64_t getVariableRoom(int32_t channel,
const std::string &variableName);
453 virtual bool setVariableBuildingPart(int32_t channel, std::string &variableName, uint64_t buildingPartId);
454 virtual void removeBuildingPartFromVariables(uint64_t buildingPartId);
455 virtual uint64_t getVariableBuildingPart(int32_t channel,
const std::string &variableName);
456 virtual bool addCategoryToVariable(int32_t channel, std::string &variableName, uint64_t categoryId);
457 virtual bool removeCategoryFromVariable(int32_t channel, std::string &variableName, uint64_t categoryId);
458 virtual void removeCategoryFromVariables(uint64_t categoryId);
459 virtual std::set<uint64_t> getVariableCategories(int32_t channel, std::string &variableName);
460 virtual bool variableHasCategory(int32_t channel,
const std::string &variableName, uint64_t categoryId);
461 virtual bool variableHasCategories(int32_t channel,
const std::string &variableName);
462 virtual bool addRoleToVariable(int32_t channel, std::string &variableName, uint64_t roleId,
RoleDirection direction,
bool invert,
bool scale,
RoleScaleInfo scaleInfo);
463 virtual bool removeRoleFromVariable(int32_t channel, std::string &variableName, uint64_t roleId);
464 virtual void removeRoleFromVariables(uint64_t roleId);
465 virtual std::unordered_map<uint64_t, Role> getVariableRoles(int32_t channel, std::string &variableName);
466 virtual bool variableHasRole(int32_t channel,
const std::string &variableName, uint64_t roleId);
467 virtual bool variableHasRoles(int32_t channel,
const std::string &variableName);
470 virtual void save(
bool savePeer,
bool saveVariables,
bool saveCentralConfig);
471 virtual void loadConfig();
472 virtual void saveConfig();
485 virtual uint64_t createParameter(
ParameterGroup::Type::Enum parameterSetType, uint32_t channel,
const std::string ¶meterName, std::vector<uint8_t> &value, int32_t remoteAddress = 0, uint32_t remoteChannel = 0);
486 virtual void saveParameter(uint32_t parameterID,
ParameterGroup::Type::Enum parameterSetType, uint32_t channel,
const std::string ¶meterName, std::vector<uint8_t> &value, int32_t remoteAddress = 0, uint32_t remoteChannel = 0);
487 virtual void saveSpecialTypeParameter(uint32_t parameterID,
490 const std::string ¶meterName,
491 std::vector<uint8_t> &value,
494 const std::string &roles);
495 virtual void saveParameter(uint32_t parameterID, uint32_t address, std::vector<uint8_t> &value);
496 virtual void saveParameter(uint32_t parameterID, std::vector<uint8_t> &value);
497 virtual void loadVariables(
ICentral *central, std::shared_ptr<BaseLib::Database::DataTable> &rows);
498 virtual void saveVariables();
499 virtual void saveVariable(uint32_t index, int32_t intValue);
500 virtual void saveVariable(uint32_t index, int64_t intValue);
501 virtual void saveVariable(uint32_t index, std::string &stringValue);
502 virtual void saveVariable(uint32_t index, std::vector<char> &binaryValue);
503 virtual void saveVariable(uint32_t index, std::vector<uint8_t> &binaryValue);
504 virtual void deleteFromDatabase();
505 virtual void savePeers() = 0;
510 virtual void homegearStarted();
515 virtual void homegearShuttingDown();
523 virtual void initializeCentralConfig();
525 virtual std::unordered_map<int32_t, std::vector<std::shared_ptr<BasicPeer>>> getPeers();
526 virtual std::shared_ptr<BasicPeer> getPeer(int32_t channel, int32_t address, int32_t remoteChannel = -1);
527 virtual std::shared_ptr<BasicPeer> getPeer(int32_t channel, uint64_t
id, int32_t remoteChannel = -1);
528 virtual std::shared_ptr<BasicPeer> getPeer(int32_t channel, std::string serialNumber, int32_t remoteChannel = -1);
529 virtual void updatePeer(uint64_t oldId, uint64_t newId);
530 virtual void updatePeer(
const std::string &old_serial_number,
const std::string &new_serial_number);
532 virtual std::shared_ptr<ICentral> getCentral() = 0;
540 virtual std::shared_ptr<std::vector<PVariable>> getDeviceDescriptions(
PRpcClientInfo clientInfo,
bool channels, std::map<std::string, bool> fields);
541 virtual PVariable getDeviceDescription(
PRpcClientInfo clientInfo, int32_t channel, std::map<std::string, bool> fields);
544 virtual PVariable getLinkInfo(
PRpcClientInfo clientInfo, int32_t senderChannel, uint64_t receiverID, int32_t receiverChannel);
545 virtual PVariable setLinkInfo(
PRpcClientInfo clientInfo, int32_t senderChannel, uint64_t receiverID, int32_t receiverChannel, std::string name, std::string description);
554 virtual PVariable getValue(
PRpcClientInfo clientInfo, uint32_t channel, std::string valueKey,
bool requestFromDevice,
bool asynchronous);
555 virtual PVariable getVariableDescription(
PRpcClientInfo clientInfo, uint32_t channel, std::string valueKey,
const std::unordered_set<std::string> &fields);
558 virtual PVariable getVariablesInRoom(
PRpcClientInfo clientInfo, uint64_t roomId,
bool returnDeviceAssigned,
bool checkAcls);
559 virtual PVariable getVariablesInBuildingPart(
PRpcClientInfo clientInfo, uint64_t buildingPartId,
bool returnDeviceAssigned,
bool checkAcls);
583 uint64_t _peerID = 0;
584 uint32_t _parentID = 0;
585 int32_t _address = 0;
590 int32_t _firmwareVersion = 0;
592 uint64_t _deviceType = 0;
594 std::unordered_map<int32_t, std::vector<std::shared_ptr<BasicPeer>>>
_peers;
596 std::unordered_map<int32_t, std::string>
_names;
607 std::unordered_map<int32_t, uint64_t>
_rooms;
621 bool _disposing =
false;
622 bool _saveTeam =
false;
623 std::atomic<int64_t> _lastPacketReceived{0};
629 virtual void raiseRemoveWebserverEventHandler();
631 virtual void raiseRPCEvent(std::string &source, uint64_t
id, int32_t channel, std::string &deviceAddress, std::shared_ptr<std::vector<std::string>> &valueKeys, std::shared_ptr<std::vector<PVariable>> &values);
632 virtual void raiseRPCUpdateDevice(uint64_t
id, int32_t channel, std::string address, int32_t hint);
633 virtual void raiseEvent(std::string &source, uint64_t peerID, int32_t channel, std::shared_ptr<std::vector<std::string>> &variables, std::shared_ptr<std::vector<PVariable>> &values);
640 virtual void onConfigPending(
bool configPending);
642 void onEvent(std::string &source, uint64_t
peerId, int32_t channel, std::shared_ptr<std::vector<std::string>> &variables, std::shared_ptr<std::vector<PVariable>> &values)
override;
643 void onRPCEvent(std::string &source, uint64_t
peerId, int32_t channel, std::string &deviceAddress, std::shared_ptr<std::vector<std::string>> &valueKeys, std::shared_ptr<std::vector<PVariable>> &values)
override;
644 void onServiceMessageEvent(
const PServiceMessage &serviceMessage)
override;
645 void onSaveParameter(std::string name, uint32_t channel, std::vector<uint8_t> &data)
override;
646 std::shared_ptr<Database::DataTable> onGetServiceMessages()
override;
648 void onDeleteServiceMessage(uint64_t databaseID)
override;
649 void onEnqueuePendingQueues()
override;
696 virtual void initializeMasterSet(int32_t channel, std::shared_ptr<ConfigParameters> masterSet);
703 virtual void initializeValueSet(int32_t channel, std::shared_ptr<Variables> valueSet);
710 virtual void initializeTypeString();
virtual bool load(ICentral *central)
Definition: Peer.h:469
std::unordered_map< uint32_t, std::unordered_map< std::string, RpcConfigurationParameter > > configCentral
Definition: Peer.h:352
Definition: BinaryPayload.cpp:36
virtual std::string getIp()
Definition: Peer.h:400
std::unordered_map< uint64_t, Role > getRoles()
Definition: Peer.h:193
virtual void setDeviceType(uint64_t value)
Definition: Peer.h:391
virtual void setFirmwareVersionString(std::string value)
Definition: Peer.h:386
std::shared_ptr< ServiceMessages > serviceMessages
Definition: Peer.h:355
virtual PVariable activateLinkParamset(PRpcClientInfo clientInfo, int32_t channel, uint64_t remoteID, int32_t remoteChannel, bool longPress)
Definition: Peer.h:535
virtual ~RpcConfigurationParameter()
Definition: Peer.h:78
bool hasCategory(uint64_t id)
Definition: Peer.h:151
std::mutex _roomMutex
Definition: Peer.h:606
virtual int32_t getAddress()
Definition: Peer.h:368
This is the base library main class.
Definition: BaseLib.h:95
virtual void setAddress(int32_t value)
Definition: Peer.h:371
Enum
Definition: HomegearDevice.h:59
static int32_t getNumber(const std::string &s, bool isHex=false)
Converts a string (decimal or hexadecimal) to an integer.
Definition: Math.cpp:226
std::shared_ptr< ICentral > _central
Definition: Peer.h:580
Definition: ServiceMessages.h:50
virtual int32_t getFirmwareVersion()
Definition: Peer.h:380
int32_t id
Definition: FileDescriptorManager.h:53
std::vector< uint8_t > data
Definition: Peer.h:317
virtual std::string getRpcTypeString()
Definition: Peer.h:436
Definition: BaseLib.cpp:34
std::shared_ptr< HomegearDevice > getRpcDevice()
Definition: Peer.h:349
std::unordered_map< uint32_t, std::unordered_map< int32_t, std::unordered_map< uint32_t, std::unordered_map< std::string, RpcConfigurationParameter > > > > linksCentral
Definition: Peer.h:354
std::shared_ptr< Array > PArray
Definition: Variable.h:72
std::shared_ptr< RpcClientInfo > PRpcClientInfo
Definition: ScriptInfo.h:47
virtual int64_t getLastPacketReceived()
Definition: Peer.h:442
virtual bool pendingQueuesEmpty()
Definition: Peer.h:443
ConfigDataBlock()
Definition: Peer.h:242
virtual uint64_t getDeviceType()
Definition: Peer.h:390
virtual bool getAllValuesHook2(PRpcClientInfo clientInfo, PParameter parameter, uint32_t channel, PVariable parameters)
Definition: Peer.h:731
std::shared_ptr< HomegearDevice > _rpcDevice
Definition: Peer.h:578
virtual ~ConfigDataBlock()
Definition: Peer.h:244
std::shared_ptr< ScriptInfo > PScriptInfo
Definition: ScriptInfo.h:56
std::unordered_map< int32_t, std::vector< std::shared_ptr< BasicPeer > > > _peers
Definition: Peer.h:594
RpcConfigurationParameter()
Definition: Peer.h:76
PVariable value
Definition: UiElements.h:217
std::shared_ptr< ParameterGroup > PParameterGroup
Definition: Parameter.h:52
std::unordered_map< int32_t, uint64_t > _buildingParts
Definition: Peer.h:609
BasicPeer()
Definition: Peer.h:298
virtual bool convertToPacketHook(RpcConfigurationParameter ¶meter, PVariable &data, std::vector< uint8_t > &result)
Definition: Peer.h:761
std::shared_ptr< Variable > PVariable
Definition: PhysicalInterfaceSettings.h:41
virtual std::string getFirmwareVersionString()
Definition: Peer.h:385
bool hasRoles()
Definition: Peer.h:198
int32_t channel
Definition: UiElements.h:215
virtual std::string getIdString()
Definition: Peer.h:405
std::string linkDescription
Definition: Peer.h:316
std::unordered_map< uint32_t, std::unordered_map< std::string, RpcConfigurationParameter > > valuesCentral
Definition: Peer.h:353
uint64_t getBuildingPart()
Definition: Peer.h:213
void setRoom(uint64_t id)
Definition: Peer.h:209
virtual bool getParamsetHook2(PRpcClientInfo clientInfo, PParameter parameter, uint32_t channel, PVariable parameters)
Definition: Peer.h:741
void addCategory(uint64_t id)
Definition: Peer.h:155
std::unordered_map< int32_t, uint64_t > _rooms
Definition: Peer.h:607
bool hasServiceRole()
Definition: Peer.h:177
virtual PVariable setInterface(PRpcClientInfo clientInfo, std::string interfaceID)
Definition: Peer.h:573
virtual void setFirmwareVersion(int32_t value)
Definition: Peer.h:381
Role getRole(uint64_t id)
Definition: Peer.h:188
std::unordered_map< uint32_t, ConfigDataBlock > binaryConfig
Definition: Peer.h:351
bool hasRole(uint64_t id)
Definition: Peer.h:173
Enum
Definition: ParameterGroup.h:63
Definition: ICentral.h:49
std::string linkName
Definition: Peer.h:315
uint64_t peerId
Definition: UiElements.h:214
virtual ~BasicPeer()
Definition: Peer.h:304
virtual std::string getSerialNumber()
Definition: Peer.h:375
static PVariable createError(int32_t faultCode, const std::string &faultString, bool retry=false)
Definition: Variable.cpp:224
virtual uint32_t getParentID()
Definition: Peer.h:367
void removeCategory(uint64_t id)
Definition: Peer.h:159
std::string _serialNumber
Definition: Peer.h:586
virtual void setIdString(std::string value)
Definition: Peer.h:406
std::map< int32_t, PEventHandler > _webserverEventHandlers
Definition: Peer.h:627
virtual PVariable forceConfigUpdate(PRpcClientInfo clientInfo)
Definition: Peer.h:536
virtual PVariable getValueFromDevice(std::shared_ptr< Parameter > ¶meter, int32_t channel, bool asynchronous)
Gets a variable value directly from the device.
Definition: Peer.h:670
virtual void enqueuePendingQueues()
Definition: Peer.h:444
std::unordered_map< int32_t, std::string > _names
Definition: Peer.h:596
DeviceDescription::PParameter rpcParameter
The RPC parameter as defined in the XML file.
Definition: Peer.h:74
std::set< uint64_t > getCategories()
Definition: Peer.h:163
std::shared_ptr< Peer > peer
Definition: Peer.h:306
std::string _typeString
Definition: Peer.h:604
RoleDirection
Definition: Role.h:19
std::map< uint32_t, uint32_t > _variableDatabaseIDs
Definition: Peer.h:579
virtual std::string getName()
Definition: Peer.h:396
virtual void setTypeString(std::string value)
Definition: Peer.h:411
std::atomic_bool deleting
Definition: Peer.h:343
virtual void setName(std::string value)
Definition: Peer.h:398
std::mutex _categoriesMutex
Definition: Peer.h:610
This class provides hooks into the web server so get and post requests can be passed into family modu...
Definition: IWebserverEventSink.h:43
virtual bool isTeam()
Definition: Peer.h:440
virtual std::string getTypeString()
Definition: Peer.h:410
virtual uint64_t getID()
Definition: Peer.h:369
std::string name
Definition: UiElements.h:216
std::unordered_map< int32_t, std::set< uint64_t > > _categories
Definition: Peer.h:611
std::string _firmwareVersionString
Definition: Peer.h:591
virtual bool convertFromPacketHook(RpcConfigurationParameter ¶meter, std::vector< uint8_t > &data, PVariable &result)
Definition: Peer.h:751
std::string serialNumber
Definition: Peer.h:311
bool hasCategories()
Definition: Peer.h:168
std::mutex _buildingPartMutex
Definition: Peer.h:608
BasicPeer(int32_t address, std::string serial, bool isVirtual)
Definition: Peer.h:299
std::mutex _peersMutex
Definition: Peer.h:593
virtual bool getAllConfigHook2(PRpcClientInfo clientInfo, PParameter parameter, uint32_t channel, PVariable parameters)
Definition: Peer.h:721
std::shared_ptr< Parameter > PParameter
Definition: Parameter.h:55
void setRpcDevice(std::shared_ptr< HomegearDevice > value)
Definition: Peer.h:345
std::string _idString
Definition: Peer.h:598
std::string _rpcTypeString
Definition: Peer.h:618
std::string _ip
Definition: Peer.h:597
uint64_t getRoom()
Definition: Peer.h:206
void setBuildingPart(uint64_t id)
Definition: Peer.h:216
virtual void setIp(std::string value)
Definition: Peer.h:401
std::shared_ptr< ServiceMessage > PServiceMessage
Definition: ServiceMessage.h:74
std::deque< std::shared_ptr< DataColumn > > DataRow
Type definition to easily create a DataRow.
Definition: DatabaseTypes.h:181
std::mutex _namesMutex
Definition: Peer.h:595