Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
hfedcba committed Apr 13, 2018
2 parents 00c63b6 + 4a97c6f commit 00ba7bb
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 119 deletions.
91 changes: 87 additions & 4 deletions misc/Device Description Files/Kodi.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
<configParameters>maint_ch_master--0</configParameters>
<variables>maint_ch_values--0</variables>
</function>
<function channel="5" type="Gui" channelCount="1">
<function channel="2" type="Application" channelCount="1">
<properties/>
<configParameters>config</configParameters>
<variables>application_valueset</variables>
</function>
<function channel="6" type="Gui" channelCount="1">
<properties/>
<configParameters>config</configParameters>
<variables>gui_valueset</variables>
Expand All @@ -25,13 +30,47 @@
<configParameters>config</configParameters>
<variables>player_valueset</variables>
</function>
<function channel="11" type="System" channelCount="1">
<function channel="14" type="System" channelCount="1">
<properties/>
<configParameters>config</configParameters>
<variables>system_valueset</variables>
</function>
</functions>
<packets>
<!-- Namespace Application -->
<packet id="Application.SetVolume">
<direction>fromCentral</direction>
<function1>Application.SetVolume</function1>
<jsonPayload>
<element>
<parameterId>VOLUME</parameterId>
</element>
</jsonPayload>
</packet>
<packet id="Application.SetMute">
<direction>fromCentral</direction>
<function1>Application.SetMute</function1>
<jsonPayload>
<element>
<parameterId>MUTE</parameterId>
</element>
</jsonPayload>
</packet>
<packet id="Application.OnVolumeChanged">
<direction>toCentral</direction>
<function1>Application.OnVolumeChanged</function1>
<channel>2</channel>
<jsonPayload>
<element>
<keyPath>params\data\volume</keyPath>
<parameterId>VOLUME</parameterId>
</element>
<element>
<keyPath>params\data\muted</keyPath>
<parameterId>MUTE</parameterId>
</element>
</jsonPayload>
</packet>
<!-- Namespace Player -->
<packet id="Player.PlayPause">
<direction>fromCentral</direction>
Expand Down Expand Up @@ -91,7 +130,7 @@
<packet id="GUI.OnScreensaverActivated">
<direction>toCentral</direction>
<function1>GUI.OnScreensaverActivated</function1>
<channel>5</channel>
<channel>6</channel>
<jsonPayload>
<element>
<parameterId>SCREENSAVER</parameterId>
Expand All @@ -102,7 +141,7 @@
<packet id="GUI.OnScreensaverDeactivated">
<direction>toCentral</direction>
<function1>GUI.OnScreensaverDeactivated</function1>
<channel>5</channel>
<channel>6</channel>
<jsonPayload>
<element>
<parameterId>SCREENSAVER</parameterId>
Expand Down Expand Up @@ -201,6 +240,50 @@
</physicalInteger>
</parameter>
</variables>
<variables id="application_valueset">
<parameter id="VOLUME">
<properties>
<casts>
<rpcBinary/>
</casts>
</properties>
<logicalInteger>
<defaultValue>0</defaultValue>
<minimumValue>0</minimumValue>
<maximumValue>100</maximumValue>
</logicalInteger>
<physicalNone groupId="VOLUME">
<operationType>store</operationType>
</physicalNone>
<packets>
<packet id="Application.OnVolumeChanged">
<type>event</type>
</packet>
<packet id="Application.SetVolume">
<type>set</type>
</packet>
</packets>
</parameter>
<parameter id="MUTE">
<properties>
<casts>
<rpcBinary/>
</casts>
</properties>
<logicalBoolean />
<physicalNone groupId="MUTE">
<operationType>store</operationType>
</physicalNone>
<packets>
<packet id="Application.OnVolumeChanged">
<type>event</type>
</packet>
<packet id="Application.SetMute">
<type>set</type>
</packet>
</packets>
</parameter>
</variables>
<variables id="gui_valueset">
<parameter id="SCREENSAVER">
<properties>
Expand Down
112 changes: 6 additions & 106 deletions src/MyCentral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ void MyCentral::deletePeer(uint64_t id)
channels->arrayValue->push_back(PVariable(new Variable(i->first)));
}

raiseRPCDeleteDevices(deviceAddresses, deviceInfo);
std::vector<uint64_t> deletedIds{ id };
raiseRPCDeleteDevices(deletedIds, deviceAddresses, deviceInfo);

{
std::lock_guard<std::mutex> peersGuard(_peersMutex);
Expand Down Expand Up @@ -349,7 +350,8 @@ std::string MyCentral::handleCliCommand(std::string command)

PVariable deviceDescriptions(new Variable(VariableType::tArray));
deviceDescriptions->arrayValue = peer->getDeviceDescriptions(nullptr, true, std::map<std::string, bool>());
raiseRPCNewDevices(deviceDescriptions);
std::vector<uint64_t> newIds{ peer->getID() };
raiseRPCNewDevices(newIds, deviceDescriptions);
GD::out.printMessage("Added peer 0x" + BaseLib::HelperFunctions::getHexString(peer->getID()) + ".");
stringStream << "Added peer " << std::to_string(peer->getID()) << " with serial number " << serialNumber << "." << std::dec << std::endl;
}
Expand Down Expand Up @@ -722,7 +724,8 @@ PVariable MyCentral::createDevice(BaseLib::PRpcClientInfo clientInfo, int32_t de

PVariable deviceDescriptions(new Variable(VariableType::tArray));
deviceDescriptions->arrayValue = peer->getDeviceDescriptions(clientInfo, true, std::map<std::string, bool>());
raiseRPCNewDevices(deviceDescriptions);
std::vector<uint64_t> newIds{ peer->getID() };
raiseRPCNewDevices(newIds, deviceDescriptions);
GD::out.printMessage("Added peer 0x" + BaseLib::HelperFunctions::getHexString(peer->getID()) + ".");

return PVariable(new Variable((uint32_t)peer->getID()));
Expand Down Expand Up @@ -797,107 +800,4 @@ PVariable MyCentral::deleteDevice(BaseLib::PRpcClientInfo clientInfo, uint64_t p
return Variable::createError(-32500, "Unknown application error.");
}

PVariable MyCentral::getDeviceInfo(BaseLib::PRpcClientInfo clientInfo, uint64_t id, std::map<std::string, bool> fields)
{
try
{
if(id > 0)
{
std::shared_ptr<MyPeer> peer(getPeer(id));
if(!peer) return Variable::createError(-2, "Unknown device.");

return peer->getDeviceInfo(clientInfo, fields);
}
else
{
PVariable array(new Variable(VariableType::tArray));

std::vector<std::shared_ptr<MyPeer>> peers;
//Copy all peers first, because listDevices takes very long and we don't want to lock _peersMutex too long
_peersMutex.lock();
for(std::map<uint64_t, std::shared_ptr<BaseLib::Systems::Peer>>::iterator i = _peersById.begin(); i != _peersById.end(); ++i)
{
peers.push_back(std::dynamic_pointer_cast<MyPeer>(i->second));
}
_peersMutex.unlock();

for(std::vector<std::shared_ptr<MyPeer>>::iterator i = peers.begin(); i != peers.end(); ++i)
{
//listDevices really needs a lot of resources, so wait a little bit after each device
std::this_thread::sleep_for(std::chrono::milliseconds(3));
PVariable info = (*i)->getDeviceInfo(clientInfo, fields);
if(!info) continue;
array->arrayValue->push_back(info);
}

return array;
}
}
catch(const std::exception& ex)
{
GD::out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what());
}
catch(BaseLib::Exception& ex)
{
GD::out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what());
}
catch(...)
{
GD::out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__);
}
return Variable::createError(-32500, "Unknown application error.");
}

PVariable MyCentral::putParamset(BaseLib::PRpcClientInfo clientInfo, std::string serialNumber, int32_t channel, ParameterGroup::Type::Enum type, std::string remoteSerialNumber, int32_t remoteChannel, PVariable paramset)
{
try
{
std::shared_ptr<MyPeer> peer(getPeer(serialNumber));
uint64_t remoteID = 0;
if(!remoteSerialNumber.empty())
{
std::shared_ptr<MyPeer> remotePeer(getPeer(remoteSerialNumber));
if(!remotePeer) return Variable::createError(-3, "Remote peer is unknown.");
remoteID = remotePeer->getID();
}
if(peer) return peer->putParamset(clientInfo, channel, type, remoteID, remoteChannel, paramset);
return Variable::createError(-2, "Unknown device.");
}
catch(const std::exception& ex)
{
GD::out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what());
}
catch(BaseLib::Exception& ex)
{
GD::out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what());
}
catch(...)
{
GD::out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__);
}
return Variable::createError(-32500, "Unknown application error.");
}

PVariable MyCentral::putParamset(BaseLib::PRpcClientInfo clientInfo, uint64_t peerID, int32_t channel, ParameterGroup::Type::Enum type, uint64_t remoteID, int32_t remoteChannel, PVariable paramset)
{
try
{
std::shared_ptr<MyPeer> peer(getPeer(peerID));
if(peer) return peer->putParamset(clientInfo, channel, type, remoteID, remoteChannel, paramset);
return Variable::createError(-2, "Unknown device.");
}
catch(const std::exception& ex)
{
GD::out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what());
}
catch(BaseLib::Exception& ex)
{
GD::out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what());
}
catch(...)
{
GD::out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__);
}
return Variable::createError(-32500, "Unknown application error.");
}
}
3 changes: 0 additions & 3 deletions src/MyCentral.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ class MyCentral : public BaseLib::Systems::ICentral
virtual PVariable createDevice(BaseLib::PRpcClientInfo clientInfo, int32_t deviceType, std::string serialNumber, int32_t address, int32_t firmwareVersion, std::string interfaceId);
virtual PVariable deleteDevice(BaseLib::PRpcClientInfo clientInfo, std::string serialNumber, int32_t flags);
virtual PVariable deleteDevice(BaseLib::PRpcClientInfo clientInfo, uint64_t peerID, int32_t flags);
virtual PVariable getDeviceInfo(BaseLib::PRpcClientInfo clientInfo, uint64_t id, std::map<std::string, bool> fields);
virtual PVariable putParamset(BaseLib::PRpcClientInfo clientInfo, std::string serialNumber, int32_t channel, ParameterGroup::Type::Enum type, std::string remoteSerialNumber, int32_t remoteChannel, PVariable paramset);
virtual PVariable putParamset(BaseLib::PRpcClientInfo clientInfo, uint64_t peerID, int32_t channel, ParameterGroup::Type::Enum type, uint64_t remoteID, int32_t remoteChannel, PVariable paramset);
protected:
virtual void init();
virtual void loadPeers();
Expand Down
29 changes: 25 additions & 4 deletions src/MyFamily.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,31 @@ PVariable MyFamily::getPairingInfo()
{
try
{
if(!_central) return PVariable(new Variable(VariableType::tArray));
PVariable array(new Variable(VariableType::tArray));
array->arrayValue->push_back(PVariable(new Variable(std::string("createDevice"))));
return array;
if(!_central) return std::make_shared<BaseLib::Variable>(BaseLib::VariableType::tStruct);
PVariable info = std::make_shared<BaseLib::Variable>(BaseLib::VariableType::tStruct);

//{{{ General
info->structValue->emplace("searchInterfaces", std::make_shared<BaseLib::Variable>(false));
//}}}

//{{{ Pairing methods
PVariable pairingMethods = std::make_shared<BaseLib::Variable>(BaseLib::VariableType::tStruct);

//{{{ createDevice
PVariable createDeviceMetadata = std::make_shared<BaseLib::Variable>(BaseLib::VariableType::tStruct);
PVariable createDeviceMetadataInfo = std::make_shared<BaseLib::Variable>(BaseLib::VariableType::tStruct);
PVariable createDeviceFields = std::make_shared<BaseLib::Variable>(BaseLib::VariableType::tArray);
createDeviceFields->arrayValue->push_back(std::make_shared<BaseLib::Variable>("serialNumber"));
createDeviceMetadataInfo->structValue->emplace("fields", createDeviceFields);
createDeviceMetadata->structValue->emplace("metadataInfo", createDeviceMetadataInfo);

pairingMethods->structValue->emplace("createDevice", createDeviceMetadata);
//}}}

info->structValue->emplace("pairingMethods", pairingMethods);
//}}}

return info;
}
catch(const std::exception& ex)
{
Expand Down
8 changes: 7 additions & 1 deletion src/MyPeer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ PParameterGroup MyPeer::getParameterSet(int32_t channel, ParameterGroup::Type::E
return PParameterGroup();
}

PVariable MyPeer::putParamset(BaseLib::PRpcClientInfo clientInfo, int32_t channel, ParameterGroup::Type::Enum type, uint64_t remoteID, int32_t remoteChannel, PVariable variables, bool onlyPushing)
PVariable MyPeer::putParamset(BaseLib::PRpcClientInfo clientInfo, int32_t channel, ParameterGroup::Type::Enum type, uint64_t remoteID, int32_t remoteChannel, PVariable variables, bool checkAcls, bool onlyPushing)
{
try
{
Expand All @@ -691,6 +691,9 @@ PVariable MyPeer::putParamset(BaseLib::PRpcClientInfo clientInfo, int32_t channe
if(!parameterGroup) return Variable::createError(-3, "Unknown parameter set.");
if(variables->structValue->empty()) return PVariable(new Variable(VariableType::tVoid));

auto central = getCentral();
if(!central) return Variable::createError(-32500, "Could not get central.");

if(type == ParameterGroup::Type::Enum::config)
{
bool configChanged = false;
Expand Down Expand Up @@ -733,6 +736,9 @@ PVariable MyPeer::putParamset(BaseLib::PRpcClientInfo clientInfo, int32_t channe
for(Struct::iterator i = variables->structValue->begin(); i != variables->structValue->end(); ++i)
{
if(i->first.empty() || !i->second) continue;

if(checkAcls && !clientInfo->acls->checkVariableWriteAccess(central->getPeer(_peerID), channel, i->first)) continue;

setValue(clientInfo, channel, i->first, i->second, true);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/MyPeer.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class MyPeer : public BaseLib::Systems::Peer, public BaseLib::Rpc::IWebserverEve
virtual void homegearShuttingDown();

//RPC methods
virtual PVariable putParamset(BaseLib::PRpcClientInfo clientInfo, int32_t channel, ParameterGroup::Type::Enum type, uint64_t remoteID, int32_t remoteChannel, PVariable variables, bool onlyPushing = false);
virtual PVariable putParamset(BaseLib::PRpcClientInfo clientInfo, int32_t channel, ParameterGroup::Type::Enum type, uint64_t remoteID, int32_t remoteChannel, PVariable variables, bool checkAcls, bool onlyPushing = false);
virtual PVariable setValue(BaseLib::PRpcClientInfo clientInfo, uint32_t channel, std::string valueKey, PVariable value, bool wait);
//End RPC methods
protected:
Expand Down

0 comments on commit 00ba7bb

Please sign in to comment.