SConscript('protocol-plugin/SConscript')
# Build notification manager project
- #if target_os not in ['android']:
- # SConscript('notification-manager/SConscript')
+ if target_os not in ['android', 'tizen']:
+ SConscript('notification-manager/SConscript')
# Build resource-manipulation project
- if target_os not in ['android']:
+ if target_os not in ['android', 'tizen']:
SConscript('resource-manipulation/SConscript')
#else:
# SConscript('notification-manager/SampleApp/arduino/SConscript')
#include "ocstack.h"
#include "logger.h"
-//#define OC_TRANSPORT CT_DEFAULT
#define OC_TRANSPORT CT_ADAPTER_IP
#ifdef __cplusplus
#define HOSTING_TAG PCF("Hosting")
/**
- * Start resource coordinator.
- * This function will create mirrorResourceList and start to discover coordinatee candidate.
+ * Start resource hosting.
+ * This function will start the resource hosting and the discovery for remote resource which want to be hosted.
*
* @return ::OC_STACK_OK upon success, ::OC_STACK_ERROR is returned except the case that OC_STACK_SUCCESS is returned.
*/
OCStackResult OICStartCoordinate();
/**
- * Stop resource coordinator.
- * This function will stop the resource hosting and delete mirrorResourceList used.
+ * Stop resource hosting.
+ * This function will stop the resource hosting and delete all hosting resource.
*
* @return ::OC_STACK_OK upon success, ::OC_STACK_ERROR is returned except the case that OC_STACK_SUCCESS is returned.
*/
{
namespace Service
{
+#define HOSTING_LOG_TAG PCF("Hosting")
+#define OIC_HOSTING_LOG(level, tag, ...) OCLogv((level), (HOSTING_LOG_TAG), __VA_ARGS__)
+
+HostingObject::HostingObject()
+: remoteObject(nullptr), mirroredServer(nullptr),
+ remoteState(ResourceState::NOT_WATCHING),
+ pStateChangedCB(nullptr), pDataUpdateCB(nullptr),
+ pDestroyCB(nullptr), pSetRequestHandler(nullptr)
+{
+}
HostingObject::RemoteObjectPtr HostingObject::getRemoteResource() const
{
void HostingObject::initializeHostingObject(RemoteObjectPtr rResource, DestroyedCallback destroyCB)
{
- mirroredServer = nullptr;
- remoteState = ResourceState::NOT_WATCHING;
remoteObject = rResource;
try
{
- remoteObject->startWatching(pStateChangedCB);
+ remoteObject->startMonitoring(pStateChangedCB);
remoteObject->startCaching(pDataUpdateCB);
- }catch(InvalidParameterException &e)
+ }catch(...)
{
- std::cout << e.what() << std::endl;
+ throw;
}
}
rObject->startCaching(pDataUpdateCB);
}catch(InvalidParameterException &e)
{
- std::cout << e.what() << std::endl;
+ OIC_HOSTING_LOG(DEBUG,
+ "[HostingObject::stateChangedCB]startCaching InvalidParameterException:%s",
+ e.what());
}
}
break;
rObject->stopCaching();
}catch(InvalidParameterException &e)
{
- std::cout << e.what() << std::endl;
+ OIC_HOSTING_LOG(DEBUG,
+ "[HostingObject::stateChangedCB]stopCaching InvalidParameterException:%s",
+ e.what());
}
}
if(rObject->isWatching() == true)
{
try
{
- std::cout << "stopWatching\n";
-// rObject->stopWatching();
+// rObject->stopMonitoring();
}catch(InvalidParameterException &e)
{
- std::cout << e.what() << std::endl;
+ OIC_HOSTING_LOG(DEBUG,
+ "[HostingObject::stateChangedCB]stopWatching InvalidParameterException:%s",
+ e.what());
}
}
- std::cout << "delete Mirrored Server\n";
mirroredServer = nullptr;
- std::cout << "delete Mirrored Server Done\n";
destroyHostingObject();
break;
}
try
{
mirroredServer = createMirroredServer(rObject);
- }catch(...)
+ }catch(PlatformException &e)
{
+ OIC_HOSTING_LOG(DEBUG,
+ "[HostingObject::dataChangedCB]createMirroredServer PlatformException:%s",
+ e.what());
mirroredServer = nullptr;
return;
}
std::string interface = interfaces.begin()->c_str();
retResource = ResourceObject::Builder(uri, type, interface).
setDiscoverable(true).setObservable(true).build();
+
// TODO need to bind types and interfaces
retResource->setAutoNotifyPolicy(ResourceObject::AutoNotifyPolicy::UPDATED);
retResource->setSetRequestHandler(pSetRequestHandler);
- }catch(PlatformException &e)
+ }catch(...)
{
- // TODO logging and throw
+ OIC_HOSTING_LOG(DEBUG, "[HostingObject::createMirroredServer] %s", "PlatformException");
throw;
}
}
else
{
- //TODO logging and throw
throw PlatformException(OC_STACK_ERROR);
}
{
try
{
- RequestObject newRequest;
+ RequestObject newRequest = { };
newRequest.invokeRequest(remoteObject, RequestObject::RequestMethod::Setter,
primitiveRequest, resourceAttibutes);
- }catch(...)
+ }catch(PlatformException &e)
{
- //TODO It is failed that setRequest send to remoteObject from mirrored server.
+ OIC_HOSTING_LOG(DEBUG,
+ "[HostingObject::setRequestHandler] PlatformException:%s",
+ e.what());
throw;
}
RCSSetResponse(const RCSRequest&, ResourceAttributes&)> SetRequestHandler;
public:
- HostingObject() = default;
+ HostingObject();
~HostingObject() = default;
void initializeHostingObject(RemoteObjectPtr rResource, DestroyedCallback destroyCB);
#define HOSTING_TAG "/hosting"
#define HOSTING_TAG_SIZE ((size_t)8)
+#define HOSTING_LOG_TAG PCF("Hosting")
+#define OIC_HOSTING_LOG(level, tag, ...) OCLogv((level), (HOSTING_LOG_TAG), __VA_ARGS__)
+
+namespace
+{
+ std::string MULTICAST_PRESENCE_ADDRESS = std::string("coap://") + OC_MULTICAST_PREFIX;
+ std::string HOSTING_RESOURSE_TYPE = "Resource.Hosting";
+}
ResourceHosting * ResourceHosting::s_instance(nullptr);
std::mutex ResourceHosting::s_mutexForCreation;
+ResourceHosting::ResourceHosting()
+: hostingObjectList(),
+ discoveryManager(nullptr),
+ presenceHandle(),
+ pPresenceCB(nullptr), pDiscoveryCB(nullptr)
+{
+}
+
ResourceHosting * ResourceHosting::getInstance()
{
if (!s_instance)
requestMulticastDiscovery();
}catch(PlatformException &e)
{
+ OIC_HOSTING_LOG(DEBUG,
+ "[ResourceHosting::startHosting]PlatformException:%s", e.what());
throw;
}catch(InvalidParameterException &e)
{
+ OIC_HOSTING_LOG(DEBUG,
+ "[ResourceHosting::startHosting]InvalidParameterException:%s", e.what());
+ throw;
+ }catch(std::exception &e)
+ {
+ OIC_HOSTING_LOG(DEBUG,
+ "[ResourceHosting::startHosting]std::exception:%s", e.what());
throw;
}
}
void ResourceHosting::stopHosting()
{
- // TODO clear list hostingObjectList
+ // clear list hostingObjectList
if(presenceHandle.isSubscribing())
{
presenceHandle.unsubscribe();
{
try
{
- presenceHandle = PresenceSubscriber(std::string("coap://") + OC_MULTICAST_PREFIX,
+ presenceHandle = PresenceSubscriber(MULTICAST_PRESENCE_ADDRESS,
OCConnectivityType::CT_DEFAULT, pPresenceCB);
}catch(...)
{
void ResourceHosting::requestDiscovery(std::string address)
{
std::string host = address;
- std::string uri = OC_RSRVD_WELL_KNOWN_URI + std::string("?rt=Resource.Hosting");
+ std::string uri = OC_RSRVD_WELL_KNOWN_URI + std::string("?rt=") + HOSTING_RESOURSE_TYPE;
OCConnectivityType type = OCConnectivityType::CT_DEFAULT;
discoveryManager->discoverResource(host, uri, type, pDiscoveryCB);
}
HostingObjectPtr foundHostingObject = findRemoteResource(remoteResource);
if(foundHostingObject == nullptr)
{
- foundHostingObject.reset(new HostingObject());
- foundHostingObject->initializeHostingObject(remoteResource,
- std::bind(&ResourceHosting::destroyedHostingObject, this, foundHostingObject));
- hostingObjectList.push_back(foundHostingObject);
- }
- else
- {
- // this resource registered
+ try
+ {
+ foundHostingObject.reset(new HostingObject());
+ foundHostingObject->initializeHostingObject(remoteResource,
+ std::bind(&ResourceHosting::destroyedHostingObject, this, foundHostingObject));
+ hostingObjectList.push_back(foundHostingObject);
+ }catch(InvalidParameterException &e)
+ {
+ OIC_HOSTING_LOG(DEBUG,
+ "[ResourceHosting::discoverHandler]InvalidParameterException:%s", e.what());
+ }
}
}
void ResourceHosting::destroyedHostingObject(HostingObjectPtr destroyedPtr)
{
- std::list<HostingObjectPtr>::iterator foundObjectIter
- = std::find(hostingObjectList.begin(), hostingObjectList.end(), destroyedPtr);
-
- if(foundObjectIter != hostingObjectList.end())
- {
- std::cout << "destroy hosting object.\n";
- hostingObjectList.erase(foundObjectIter);
- }
+ hostingObjectList.remove(destroyedPtr);
}
} /* namespace Service */
static ResourceHosting * getInstance();
private:
- ResourceHosting() = default;
+ ResourceHosting();
~ResourceHosting() = default;
ResourceHosting(const ResourceHosting&) = delete;
#include "logger.h"
#include "ResourceHosting.h"
-#define OC_TRANSPORT CT_ADAPTER_IP
-#define HOSTING_TAG PCF("Hosting")
-
namespace
{
+ #define OC_TRANSPORT CT_ADAPTER_IP
+ #define HOSTING_TAG PCF("Hosting")
+ #define OIC_HOSTING_LOG(level, tag, ...) OCLogv((level), (HOSTING_TAG), __VA_ARGS__)
OIC::Service::ResourceHosting * rhInstance = OIC::Service::ResourceHosting::getInstance();
}
try
{
rhInstance->startHosting();
+ }catch(OIC::Service::PlatformException &e)
+ {
+ OIC_HOSTING_LOG(DEBUG, "[OICStartCoordinate] platformException, reason:%s", e.what());
+ retResult = OC_STACK_ERROR;
+ throw;
+ }catch(OIC::Service::InvalidParameterException &e)
+ {
+ OIC_HOSTING_LOG(DEBUG,
+ "[OICStartCoordinate] InvalidParameterException, reason:%s", e.what());
+ retResult = OC_STACK_ERROR;
+ throw;
}catch(...)
{
+ OIC_HOSTING_LOG(DEBUG, "[OICStartCoordinate] Unknown Exception", "");
retResult = OC_STACK_ERROR;
}
const int SUCCESS_RESPONSE = OC_STACK_OK;
-#define OC_WELL_KNOWN_COORDINATING_QUERY "/oc/core?rt=Resource.Hosting"
+#define OC_WELL_KNOWN_COORDINATING_QUERY "/oic/res?rt=Resource.Hosting"
#define OBSERVE 1
#define GET 2