#include <iostream>
#include "RCSDiscoveryManager.h"
+#include "RCSRepresentation.h"
#include "RCSRemoteResourceObject.h"
#include "RCSResourceAttributes.h"
#include "RCSAddress.h"
{
assert(min <= max);
- int input;
+ int input = 0;
std::cin >> input;
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
- if (!std::cin.fail() && min <= input && input <= max) return input;
+ if (!std::cin.fail() && min <= input && input <= max)
+ {
+ return input;
+ }
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
const auto width = (items.size() + 1) / 10 + 1;
- for(size_t i = 0; i < items.size(); ++i)
+ for (size_t i = 0; i < items.size(); ++i)
{
displayItem(width, i + 1, items[i]);
}
{
int selected = processUserInput(1, items.size() + 1) - 1;
- if(selected == static_cast<int>(items.size())) throw CloseApp();
+ if (selected == static_cast<int>(items.size()))
+ {
+ throw CloseApp();
+ }
onSelected(items[selected]);
}
selectItem(items);
}
+std::string inputInterface()
+{
+ std::string interfaceName;
+
+ std::cout << "\tInput the Interface you want to set : ";
+ std::cin >> interfaceName;
+
+ return interfaceName;
+}
+
+RCSResourceAttributes inputKeyValue()
+{
+ std::string key;
+
+ std::cout << "\tEnter the Key you want to set : ";
+ std::cin >> key;
+
+ std::cout << "\tEnter the value(INT) you want to set :";
+ RCSResourceAttributes attrs;
+ attrs[key] = processUserInput();
+
+ return attrs;
+}
+
void printAttribute(const std::string& key, const RCSResourceAttributes::Value& value)
{
std::cout << "\tkey : " << key << std::endl
std::cout << "\tattributes is empty" << std::endl;
}
- for(const auto& attr : attributes)
+ for (const auto& attr : attributes)
{
printAttribute(attr.key(), attr.value());
}
}
+void print(const std::string& name, const std::vector< std::string >& elements)
+{
+ if (elements.empty())
+ {
+ std::cout << "\t" << name << " is empty" << std::endl;
+ return;
+ }
+
+ std::cout << "\t" << name << " : " << std::endl;
+ for (const auto& item : elements)
+ {
+ std::cout << item << " ";
+ }
+ std::cout << std::endl;
+}
+
+void printUri(const std::string& uri)
+{
+ if (uri.empty())
+ {
+ std::cout << "\turi is empty" << std::endl;
+ }
+ else
+ {
+ std::cout << "\turi : " << uri << std::endl;
+ }
+}
+
+void printRepresentation(const RCSRepresentation& rep)
+{
+ printUri(rep.getUri());
+ print("interfaces", rep.getInterfaces());
+ print("resourceTypes", rep.getResourceTypes());
+ printAttributes(rep.getAttributes());
+
+ const auto& children = rep.getChildren();
+
+ if (children.empty())
+ {
+ std::cout << "\tchildren is empty" << std::endl;
+ }
+ else
+ {
+ int cnt = 0;
+ for (const auto& child : children)
+ {
+ std::cout << "========================================================" << std::endl;
+ std::cout << ++cnt << " chlid" << std::endl;
+ printRepresentation(child);
+ std::cout << "========================================================" << std::endl;
+ }
+ }
+}
+
void onResourceStateChanged(ResourceState resourceState)
{
std::cout << "onResourceStateChanged callback" << std::endl;
- switch(resourceState)
+ switch (resourceState)
{
case ResourceState::NONE:
std::cout << "\tState changed to : NOT_MONITORING" << std::endl;
}
}
-void onCacheUpdated(const RCSResourceAttributes& attributes)
+void onCacheUpdated(const RCSResourceAttributes& attributes, int eCode)
{
- std::cout << "onCacheUpdated callback" << std::endl;
+ std::cout << "onCacheUpdated callback : " << eCode << std::endl;
printAttributes(attributes);
}
printAttributes(attributes);
}
+void onRemoteGetReceived(const HeaderOpts&, const RCSRepresentation& rep, int)
+{
+ std::cout << "onRemoteGetReceived callback" << std::endl;
+
+ printRepresentation(rep);
+}
+
+void onRemoteSetReceived(const HeaderOpts&, const RCSRepresentation& rep, int)
+{
+ std::cout << "onRemoteSetReceived callback" << std::endl;
+
+ printRepresentation(rep);
+}
+
void startMonitoring()
{
if (g_selectedResource->isMonitoring())
void setRemoteAttributes()
{
- std::string key;
+ g_selectedResource->setRemoteAttributes(inputKeyValue(), onRemoteAttributesReceived);
+}
- std::cout << "\tEnter the Key you want to set : ";
- std::cin >> key;
+void getWithInterface()
+{
+ RCSQueryParams queryParams;
+ queryParams.setResourceInterface(inputInterface());
- std::cout << "\tEnter the value(INT) you want to set :";
- RCSResourceAttributes attrs;
- attrs[key] = processUserInput();
+ g_selectedResource->get(queryParams, onRemoteGetReceived);
+}
+
+void setWithInterface()
+{
+ RCSQueryParams queryParams;
+ queryParams.setResourceInterface(inputInterface());
- g_selectedResource->setRemoteAttributes(attrs, onRemoteAttributesReceived);
+ g_selectedResource->set(queryParams, inputKeyValue(), onRemoteSetReceived);
}
void startCaching(RCSRemoteResourceObject::CacheUpdatedCallback cb)
void stopCaching()
{
- if(!g_selectedResource->isCaching())
+ if (!g_selectedResource->isCaching())
{
std::cout << "\tCaching not started..." << std::endl;
return;
switch (processUserInput(RESOURCE_TEMP, RESOURCE_LIGHT))
{
- case RESOURCE_TEMP:
- g_attrKey = "Temperature";
- return RESOURCE_TYPE_TEMP;
- case RESOURCE_LIGHT:
- g_attrKey = "Brightness";
- return RESOURCE_TYPE_LIGHT;
+ case RESOURCE_TEMP:
+ {
+ g_attrKey = "Temperature";
+ return RESOURCE_TYPE_TEMP;
+ }
+ case RESOURCE_LIGHT:
+ {
+ g_attrKey = "Brightness";
+ return RESOURCE_TYPE_LIGHT;
+ }
}
throw std::logic_error("unreachable");
std::string address;
- if(std::cin.peek() != '\n') std::cin >> address;
+ if (std::cin.peek() != '\n')
+ {
+ std::cin >> address;
+ }
return address.empty() ? RCSAddress::multicast() : RCSAddress::unicast(address);
}
{
std::cout << "onResourceDiscovered callback :: " << std::endl;
- std::cout << "luri : " << discoveredResource->getUri() << std::endl;
+ std::cout << "uri : " << discoveredResource->getUri() << std::endl;
std::cout << "host address : " << discoveredResource->getAddress() << std::endl;
g_discoveredResources.push_back(discoveredResource);
auto discoveryTask = RCSDiscoveryManager::getInstance()->discoverResourceByType(address,
resourceType, onResourceDiscovered);
- while(processUserInput() != 1);
+ while (processUserInput() != 1);
discoveryTask->cancel();
}
DECLARE_MENU(stopMonitoring),
DECLARE_MENU(getRemoteAttributes),
DECLARE_MENU(setRemoteAttributes),
+ DECLARE_MENU(getWithInterface),
+ DECLARE_MENU(setWithInterface),
DECLARE_MENU(startCachingWithoutCallback),
DECLARE_MENU(startCachingWithCallback),
DECLARE_MENU(getResourceCacheState),
handleItems(discoveryMenuItems);
- if (g_discoveredResources.empty()) throw std::runtime_error("No resource found!");
+ if (g_discoveredResources.empty())
+ {
+ throw std::runtime_error("No resource found!");
+ }
g_currentRun = runResourceSelection;
}