Commit 63935648 authored by hunje.yeon's avatar hunje.yeon

Merge 'resource-manipulation' features into '0.9.2-dev' branch

Add resource manipulation features such as resource container, broker, cache and server builder.
It also includes API references at /resource/docs/Doxyfile.

Change-Id: Id72cf1d99fe6d19a62f3b8f8e57c96ca91120c6b
Signed-off-by: default avatarhunje.yeon <hunje.yeon@samsung.com>
parents 400a3dce 247861e2
......@@ -672,7 +672,8 @@ INPUT = . \
../../service/things-manager/sdk/inc \
../../service/soft-sensor-manager/SDK/cpp/include \
../../service/protocol-plugin/plugin-manager/src/PluginManager.h \
../../service/notification-manager/NotificationManager/include/hosting.h
../../service/notification-manager/NotificationManager/include/hosting.h \
../../service/resource-manipulation/include \
# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is
......
......@@ -33,14 +33,18 @@ if target_os not in ['arduino','darwin','ios']:
# Build soft sensor manager project
SConscript('soft-sensor-manager/SConscript')
# Build notification manager project
SConscript('notification-manager/SConscript')
# Build protocol plugin project
# protocol-plugin use 'inotify', this feature isn't support by MAC OSX
if target_os not in ['darwin', 'ios']:
if target_os not in ['darwin', 'ios', 'android']:
SConscript('protocol-plugin/SConscript')
# Build notification manager project
if target_os not in ['android', 'tizen']:
SConscript('notification-manager/SConscript')
# Build resource-manipulation project
if target_os not in ['android', 'tizen']:
SConscript('resource-manipulation/SConscript')
#else:
# SConscript('notification-manager/SampleApp/arduino/SConscript')
......@@ -30,7 +30,6 @@
#include "ocstack.h"
#include "logger.h"
//#define OC_TRANSPORT CT_DEFAULT
#define OC_TRANSPORT CT_ADAPTER_IP
#ifdef __cplusplus
......@@ -40,16 +39,16 @@ extern "C" {
#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.
*/
......
//******************************************************************
//
// Copyright 2015 Samsung Electronics All Rights Reserved.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#include "HostingObject.h"
namespace OIC
{
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_MONITORING),
pStateChangedCB(nullptr), pDataUpdateCB(nullptr),
pDestroyCB(nullptr), pSetRequestHandler(nullptr)
{
}
HostingObject::RemoteObjectPtr HostingObject::getRemoteResource() const
{
return remoteObject;
}
void HostingObject::initializeHostingObject(RemoteObjectPtr rResource, DestroyedCallback destroyCB)
{
remoteObject = rResource;
pStateChangedCB = std::bind(&HostingObject::stateChangedCB, this,
std::placeholders::_1, remoteObject);
pDataUpdateCB = std::bind(&HostingObject::dataChangedCB, this,
std::placeholders::_1, remoteObject);
pDestroyCB = destroyCB;
pSetRequestHandler = std::bind(&HostingObject::setRequestHandler, this,
std::placeholders::_1, std::placeholders::_2);
try
{
remoteObject->startMonitoring(pStateChangedCB);
remoteObject->startCaching(pDataUpdateCB);
}catch(...)
{
throw;
}
}
void HostingObject::destroyHostingObject()
{
pDestroyCB();
}
void HostingObject::stateChangedCB(ResourceState state, RemoteObjectPtr rObject)
{
remoteState = state;
switch (state)
{
case ResourceState::ALIVE:
{
if(rObject->isCaching() == false)
{
try
{
rObject->startCaching(pDataUpdateCB);
}catch(InvalidParameterException &e)
{
OIC_HOSTING_LOG(DEBUG,
"[HostingObject::stateChangedCB]startCaching InvalidParameterException:%s",
e.what());
}
}
break;
}
case ResourceState::LOST_SIGNAL:
case ResourceState::DESTROYED:
{
if(rObject->isCaching() == true)
{
try
{
rObject->stopCaching();
}catch(InvalidParameterException &e)
{
OIC_HOSTING_LOG(DEBUG,
"[HostingObject::stateChangedCB]stopCaching InvalidParameterException:%s",
e.what());
}
}
if(rObject->isMonitoring() == true)
{
try
{
// rObject->stopMonitoring();
}catch(InvalidParameterException &e)
{
OIC_HOSTING_LOG(DEBUG,
"[HostingObject::stateChangedCB]stopWatching InvalidParameterException:%s",
e.what());
}
}
mirroredServer = nullptr;
destroyHostingObject();
break;
}
default:
// not support of state
break;
}
}
void HostingObject::dataChangedCB(const ResourceAttributes & attributes, RemoteObjectPtr rObject)
{
if(attributes.empty())
{
return;
}
if(mirroredServer == nullptr)
{
try
{
mirroredServer = createMirroredServer(rObject);
}catch(PlatformException &e)
{
OIC_HOSTING_LOG(DEBUG,
"[HostingObject::dataChangedCB]createMirroredServer PlatformException:%s",
e.what());
mirroredServer = nullptr;
return;
}
}
ResourceAttributes rData;
{
ResourceObject::LockGuard guard(mirroredServer);
rData = mirroredServer->getAttributes();
}
if(rData.empty() || rData != attributes)
{
{
ResourceObject::LockGuard guard(mirroredServer);
for(auto it = rData.begin(); ; ++it)
{
if(it == rData.end())
{
break;
}
mirroredServer->removeAttribute(it->key());
}
for(auto it = attributes.begin();; ++it)
{
if(it == attributes.end())
{
break;
}
mirroredServer->setAttribute(it->key(), it->value());
}
}
}
}
HostingObject::ResourceObjectPtr HostingObject::createMirroredServer(RemoteObjectPtr rObject)
{
ResourceObjectPtr retResource = nullptr;
if(rObject != nullptr)
{
std::string fulluri = rObject->getUri();
std::string uri = fulluri.substr(0, fulluri.size()-8);
std::vector<std::string> types = rObject->getTypes();
std::vector<std::string> interfaces = rObject->getInterfaces();
try
{
std::string type = types.begin()->c_str();
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(...)
{
OIC_HOSTING_LOG(DEBUG, "[HostingObject::createMirroredServer] %s", "PlatformException");
throw;
}
}
else
{
throw PlatformException(OC_STACK_ERROR);
}
return retResource;
}
RCSSetResponse HostingObject::setRequestHandler(const RCSRequest & primitiveRequest,
ResourceAttributes & resourceAttibutes)
{
try
{
RequestObject newRequest = { };
newRequest.invokeRequest(remoteObject, RequestObject::RequestMethod::Setter,
primitiveRequest, resourceAttibutes);
}catch(PlatformException &e)
{
OIC_HOSTING_LOG(DEBUG,
"[HostingObject::setRequestHandler] PlatformException:%s",
e.what());
throw;
}
return RCSSetResponse::create(resourceAttibutes);
}
} /* namespace Service */
} /* namespace OIC */
//******************************************************************
//
// Copyright 2015 Samsung Electronics All Rights Reserved.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#ifndef RH_HOSTINGOBJECT_H_
#define RH_HOSTINGOBJECT_H_
#include "ResourceClient.h"
#include "ResourceObject.h"
#include "RequestObject.h"
#include "ResourceBroker.h"
#include "ResourceCacheManager.h"
#include "PrimitiveResource.h"
namespace OIC
{
namespace Service
{
class HostingObject
{
private:
typedef std::shared_ptr<ResourceObject> ResourceObjectPtr;
typedef std::shared_ptr<RemoteResourceObject> RemoteObjectPtr;
typedef std::shared_ptr<RequestObject> RequestObjectPtr;
typedef std::shared_ptr<PrimitiveResource> PrimiteveResourcePtr;
typedef std::function<void(ResourceState)> BrokerCallback;
typedef std::function<void(const ResourceAttributes &)> CacheCallback;
typedef std::function<void()> DestroyedCallback;
typedef std::function<
RCSSetResponse(const RCSRequest&, ResourceAttributes&)> SetRequestHandler;
public:
HostingObject();
~HostingObject() = default;
void initializeHostingObject(RemoteObjectPtr rResource, DestroyedCallback destroyCB);
RemoteObjectPtr getRemoteResource() const;
private:
RemoteObjectPtr remoteObject;
ResourceObjectPtr mirroredServer;
ResourceState remoteState;
BrokerCallback pStateChangedCB;
CacheCallback pDataUpdateCB;
DestroyedCallback pDestroyCB;
SetRequestHandler pSetRequestHandler;
ResourceObjectPtr createMirroredServer(RemoteObjectPtr rObject);
void stateChangedCB(ResourceState state, RemoteObjectPtr rObject);
void dataChangedCB(const ResourceAttributes & attributes, RemoteObjectPtr rObject);
RCSSetResponse setRequestHandler(
const RCSRequest & request, ResourceAttributes & attributes);
void destroyHostingObject();
};
} /* namespace Service */
} /* namespace OIC */
#endif /* RH_HOSTINGOBJECT_H_ */
//******************************************************************
//
// Copyright 2015 Samsung Electronics All Rights Reserved.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#include "RequestObject.h"
namespace OIC
{
namespace Service
{
void RequestObject::invokeRequest(RemoteObjectPtr remoteObject, RequestMethod method,
const RCSRequest & pRequest, ResourceAttributes & resourceAttibutes)
{
try
{
switch (method)
{
case RequestMethod::Setter:
remoteObject->setRemoteAttributes(resourceAttibutes,
std::bind(&RequestObject::setRequestCB, this,
std::placeholders::_1, resourceAttibutes));
break;
case RequestMethod::Getter:
case RequestMethod::Delete:
default:
// unknown type of method.
break;
}
}catch(...)
{
throw;
}
}
void RequestObject::setRequestCB(const ResourceAttributes & returnedAttributes,
ResourceAttributes & putAttibutes)
{
if(putAttibutes != returnedAttributes)
{
// TODO fail set attributes
}
}
} /* namespace Service */
} /* namespace OIC */
//******************************************************************
//
// Copyright 2015 Samsung Electronics All Rights Reserved.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#ifndef RH_REQUESTOBJECT_H_
#define RH_REQUESTOBJECT_H_
#include "ResourceClient.h"
#include "ResourceObject.h"
namespace OIC
{
namespace Service
{
class RequestObject
{
public:
typedef std::shared_ptr<RemoteResourceObject> RemoteObjectPtr;
enum class RequestMethod
{
Getter = 0,
Setter,
Delete
};
RequestObject() = default;
~RequestObject() = default;
void invokeRequest(RemoteObjectPtr remoteObject, RequestMethod method,
const RCSRequest & pRequest, ResourceAttributes & resourceAttibutes);
private:
void setRequestCB(const ResourceAttributes & returnedAttributes,
ResourceAttributes & putAttibutes);
};
} /* namespace Service */
} /* namespace OIC */
#endif /* RH_REQUESTOBJECT_H_ */
//******************************************************************
//
// Copyright 2015 Samsung Electronics All Rights Reserved.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#include "ResourceHosting.h"
#include "PresenceSubscriber.h"
#include "OCPlatform.h"
namespace OIC
{
namespace Service
{
#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);