From fccf5869819f93043e11b69c363bea3194b0b694 Mon Sep 17 00:00:00 2001 From: "doil.kwon" Date: Wed, 15 Apr 2015 04:29:16 -0700 Subject: [PATCH] Fixed notification manager caused by CA merge issue 1) modify request parameters. (add ConnectivityType) 2) fix sconscript. (include glib2.0, CAlib) Change-Id: Ie16b774438a6df9cced9f4d13c990e1f160ea0c8 Signed-off-by: doil_kwon Reviewed-on: https://gerrit.iotivity.org/gerrit/732 Tested-by: jenkins-iotivity Reviewed-by: Uze Choi --- service/SConscript | 2 +- .../NotificationManager/include/HostingConfig.h | 66 ----- .../NotificationManager/include/HostingHandler.h | 67 ----- .../NotificationManager/include/HostingInterface.h | 48 ---- .../include/NotificationManager.h | 83 ------ .../include/OICPlatformConfig.h | 51 ---- .../NotificationManager/include/ResourceManager.h | 76 ----- .../include/VirtualRepresentation.h | 82 ------ .../NotificationManager/include/hosting.h | 1 - .../NotificationManager/src/HostingHandler.cpp | 220 --------------- .../NotificationManager/src/HostingInterface.cpp | 148 ---------- .../src/NotificationManager.cpp | 162 ----------- .../NotificationManager/src/OICPlatformConfig.cpp | 80 ------ .../src/RegistrationManager.cpp | 109 -------- .../NotificationManager/src/ResourceManager.cpp | 232 ---------------- .../src/VirtualRepresentation.cpp | 231 ---------------- .../NotificationManager/src/hosting.c | 13 +- .../NotificationManager/src/linux/main.cpp | 66 ----- .../NotificationManager/src/virtualResource.c | 0 .../NotificationManager/src/virtualResource.h | 1 - service/notification-manager/SConscript | 4 +- .../SampleApp/linux/SConscript | 47 ++-- .../SampleApp/linux/notificationManager/main.c | 14 +- .../linux/sampleConsumer/SampleConsumer.cpp | 305 +++++++++++---------- .../linux/sampleProvider/SampleProvider.cpp | 144 +++++++--- 25 files changed, 298 insertions(+), 1954 deletions(-) delete mode 100644 service/notification-manager/NotificationManager/include/HostingConfig.h delete mode 100644 service/notification-manager/NotificationManager/include/HostingHandler.h delete mode 100644 service/notification-manager/NotificationManager/include/HostingInterface.h delete mode 100644 service/notification-manager/NotificationManager/include/NotificationManager.h delete mode 100644 service/notification-manager/NotificationManager/include/OICPlatformConfig.h delete mode 100644 service/notification-manager/NotificationManager/include/ResourceManager.h delete mode 100644 service/notification-manager/NotificationManager/include/VirtualRepresentation.h delete mode 100644 service/notification-manager/NotificationManager/src/HostingHandler.cpp delete mode 100644 service/notification-manager/NotificationManager/src/HostingInterface.cpp delete mode 100644 service/notification-manager/NotificationManager/src/NotificationManager.cpp delete mode 100644 service/notification-manager/NotificationManager/src/OICPlatformConfig.cpp delete mode 100644 service/notification-manager/NotificationManager/src/RegistrationManager.cpp delete mode 100644 service/notification-manager/NotificationManager/src/ResourceManager.cpp delete mode 100644 service/notification-manager/NotificationManager/src/VirtualRepresentation.cpp delete mode 100644 service/notification-manager/NotificationManager/src/linux/main.cpp mode change 100644 => 100755 service/notification-manager/NotificationManager/src/virtualResource.c mode change 100644 => 100755 service/notification-manager/SConscript mode change 100644 => 100755 service/notification-manager/SampleApp/linux/SConscript mode change 100644 => 100755 service/notification-manager/SampleApp/linux/notificationManager/main.c mode change 100644 => 100755 service/notification-manager/SampleApp/linux/sampleConsumer/SampleConsumer.cpp diff --git a/service/SConscript b/service/SConscript index 337ac13..183818d 100644 --- a/service/SConscript +++ b/service/SConscript @@ -39,7 +39,7 @@ if target_os not in ['arduino','darwin']: SConscript('protocol-plugin/SConscript') # Build notification manager project -# SConscript('notification-manager/SConscript') + SConscript('notification-manager/SConscript') #else: # SConscript('notification-manager/SampleApp/arduino/SConscript') diff --git a/service/notification-manager/NotificationManager/include/HostingConfig.h b/service/notification-manager/NotificationManager/include/HostingConfig.h deleted file mode 100644 index fa55ad2..0000000 --- a/service/notification-manager/NotificationManager/include/HostingConfig.h +++ /dev/null @@ -1,66 +0,0 @@ -//****************************************************************** -// -// Copyright 2014 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 HOSTINGCONFIG_H_ -#define HOSTINGCONFIG_H_ - -#include "NotificationManager.h" - - -enum class HostingMode -{ - None, - ManualMode, - AutomaticMode, -}; - -enum class AutomaticMethod -{ - None, - NetworkStatusChange, - Timer, - DeviceStatus -}; - -enum class NotifyMethod -{ - Frequence, - Equalization, - Granularity, - None -}; - -enum class NotifyFrequency -{ - OnTime, - Periodically, - None -}; - - -struct HostingConfig -{ - HostingMode hostingMode; - AutomaticMethod automaticMethod; - NotifyMethod notifyMethod; - NotifyFrequency frequency; -}; - -#endif /* HOSTINGCONFIG_H_ */ diff --git a/service/notification-manager/NotificationManager/include/HostingHandler.h b/service/notification-manager/NotificationManager/include/HostingHandler.h deleted file mode 100644 index 3f2170f..0000000 --- a/service/notification-manager/NotificationManager/include/HostingHandler.h +++ /dev/null @@ -1,67 +0,0 @@ -//****************************************************************** -// -// Copyright 2014 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 HOSTINGHANDLER_H_ -#define HOSTINGHANDLER_H_ - -#include "NotificationManager.h" - -class HostingHandler -{ - public: - - static void initialize(); - static void initialize(HostingConfig cfg); - static HostingHandler *getInstance(); - - void setHostingConfig(HostingConfig cfg); - - void changeHostingMode(HostingMode hostingMode, AutomaticMethod autoMethod = AutomaticMethod::None); - void changeAutomaticHostingMethod(AutomaticMethod autoMethod); - void changeNotifiyMethod(NotifyMethod notifyMethod); - void changeNotifyFrequencyType(NotifyFrequency notifyFrequency); - - private: - - HostingHandler(); - ~HostingHandler(); - - static HostingHandler *s_instance; - static mutex s_mutexForCreation; - - HostingConfig hostingCfg; - - static std::function< void(bool isHosting) > s_findHostingCandidate; - static std::function< void(std::string) > s_addExtraStr; - static std::function< void(std::shared_ptr< OCResource > resource) > s_startHosting; - static std::function< void(OCResourceHandle resourceHandle) > s_notify; - - void startFindHost(); - void onObserve(AttributeMap &AttMap, OCResourceHandle resourceHandle); - void onFoundCandidate(std::shared_ptr< OCResource > resource); - - void runAutomaticHosting(AutomaticMethod autoMethod); - void stopAutomaticHosting(); - - void notifyFrequence(OCResourceHandle resourceHandle); - -}; - -#endif /* HOSTINGHANDLER_H_ */ diff --git a/service/notification-manager/NotificationManager/include/HostingInterface.h b/service/notification-manager/NotificationManager/include/HostingInterface.h deleted file mode 100644 index 7af558f..0000000 --- a/service/notification-manager/NotificationManager/include/HostingInterface.h +++ /dev/null @@ -1,48 +0,0 @@ -//****************************************************************** -// -// Copyright 2014 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 HOSTINGINTERFACE_H_ -#define HOSTINGINTERFACE_H_ - -#include "NotificationManager.h" - -using namespace OC; -using namespace OCPlatform; - -class HostingInterface -{ - - public: - HostingInterface(); - ~HostingInterface(); - - int setOnFoundHostingCandidate( - std::function< void(std::shared_ptr< OCResource > resource) > func); - int setOnObserve(std::function< void(AttributeMap &inputAttMap, OCResourceHandle resourceHandle) > - func); - - int setFindHosting(std::function< void(bool isHosting) > &func); - int setStartHosting(std::function< void(std::shared_ptr< OCResource > resource) > &func); - int setNotifyObservers(std::function< void(OCResourceHandle resourceHandle) > &func); - int setAddExtraStr(std::function< void(std::string) > &func); - -}; - -#endif /* HOSTINGINTERFACE_H_ */ diff --git a/service/notification-manager/NotificationManager/include/NotificationManager.h b/service/notification-manager/NotificationManager/include/NotificationManager.h deleted file mode 100644 index e4909de..0000000 --- a/service/notification-manager/NotificationManager/include/NotificationManager.h +++ /dev/null @@ -1,83 +0,0 @@ -//****************************************************************** -// -// Copyright 2014 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 NOTIFICATIONMANAGER_H_ -#define NOTIFICATIONMANAGER_H_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "OICPlatformConfig.h" -#include "HostingConfig.h" -#include "ResourceManager.h" -#include "RegistrationManager.h" -#include "VirtualRepresentation.h" -#include "HostingHandler.h" -#include "HostingInterface.h" - -#include -#include -#include -#include -#include -#include -#include - -#define IN -#define OUT - -using namespace OC; -using namespace OCPlatform; - -const std::string VIRTURL_TAG = "/virtual"; - -class NotificationManager -{ - - private: - - NotificationManager(); - NotificationManager(HostingConfig cfg); - ~NotificationManager(); - - static NotificationManager *s_instance; - static mutex s_mutexForCreation; - - int getNetInfo(IN int &sck, IN struct ifreq *item, OUT std::string &ip_addres); - bool scanAndGetNetworkInterface(OUT std::string &ip_addres); - - public: - - static void initialize(); - static void initialize(HostingConfig cfg); - static NotificationManager *getInstance(); - - void registerHostingEventListener(); - -}; - -#endif /* NOTIFICATIONMANAGER_H_ */ diff --git a/service/notification-manager/NotificationManager/include/OICPlatformConfig.h b/service/notification-manager/NotificationManager/include/OICPlatformConfig.h deleted file mode 100644 index fffd71c..0000000 --- a/service/notification-manager/NotificationManager/include/OICPlatformConfig.h +++ /dev/null @@ -1,51 +0,0 @@ -//****************************************************************** -// -// Copyright 2014 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 OICPLATFORMCONFIG_H_ -#define OICPLATFORMCONFIG_H_ - -#include "OCApi.h" -#include "OCPlatform.h" -#include "OCResource.h" -#include "OCResourceRequest.h" -#include "OCResourceResponse.h" -#include "ocstack.h" - -using namespace OC; -using namespace OCPlatform; - -class OICPlatformConfig -{ - private: - - OICPlatformConfig(); - ~OICPlatformConfig(); - - static OICPlatformConfig *s_instance; - static mutex s_mutexForCreation; - static PlatformConfig s_cfg; - - public: - - void initialize(); - static OICPlatformConfig *getInstance(); - void setIP(std::string ipaddress); -}; - -#endif /* OICPLATFORMCONFIG_H_ */ diff --git a/service/notification-manager/NotificationManager/include/ResourceManager.h b/service/notification-manager/NotificationManager/include/ResourceManager.h deleted file mode 100644 index bd8c257..0000000 --- a/service/notification-manager/NotificationManager/include/ResourceManager.h +++ /dev/null @@ -1,76 +0,0 @@ -//****************************************************************** -// -// Copyright 2014 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 RESOURCEMANAGER_H_ -#define RESOURCEMANAGER_H_ - -#include "NotificationManager.h" - -using namespace OC; -using namespace OCPlatform; - - -class OICPlatformConfig; -class VirtualRepresentation; - -class ResourceManager -{ - - private: - ResourceManager(); - ~ResourceManager(); - - static ResourceManager *s_instance; - static mutex s_mutexForCreation; - static std::list< VirtualRepresentation > s_resourceList; - static std::string s_extraStr; - - void foundResourceforhosting(std::shared_ptr< OCResource > resource); - - void checkResourceDBPolicy(); - void saveResourceDB(); - - public: - - std::function< void(std::shared_ptr< OCResource > resource) > m_onFoundforHosting; - std::function< void(AttributeMap &inputAttMap, OCResourceHandle resourceHandle) > m_onObserve; - std::function< void(OCResourceHandle resourceHandle) > m_notify; - - static ResourceManager *getInstance(); - - void findNMResource(bool isHosting); - - void onFoundforHostingDefault(std::shared_ptr< OCResource > resource); - void onObserveDefault(AttributeMap &inputAttMap, OCResourceHandle resourceHandle); - void notifyObserversDefault(OCResourceHandle resourceHandle); - - void startHosting(std::shared_ptr< OCResource > resource); - void notifyObservers(OCResourceHandle resourceHandle); - - VirtualRepresentation findVirtualRepresentation(std::string uri); - AttributeMap copyAttributeMap(AttributeMap &inputAttMap); - bool isEmptyAttributeMap(AttributeMap &inputAttMap); - void printAttributeMap(AttributeMap &inputAttMap); - - void addExtraStr(std::string str); - std::string getExtraStr(); -}; - -#endif /* RESOURCEMANAGER_H_ */ diff --git a/service/notification-manager/NotificationManager/include/VirtualRepresentation.h b/service/notification-manager/NotificationManager/include/VirtualRepresentation.h deleted file mode 100644 index aa9d131..0000000 --- a/service/notification-manager/NotificationManager/include/VirtualRepresentation.h +++ /dev/null @@ -1,82 +0,0 @@ -//****************************************************************** -// -// Copyright 2014 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 VIRTUALREPRESENTATION_H_ -#define VIRTUALREPRESENTATION_H_ - -#include "NotificationManager.h" - -#define SUCCESS_RESPONSE 0 - -using namespace OC; -using namespace OCPlatform; -using namespace std; - -class ResourceManager; - -class VirtualRepresentation -{ - - private: - std::string m_virtualUri; - std::string m_originHostIP; - std::string m_resourceTypeName; - std::string m_resourceInterface; - uint8_t m_resourceProperty; - - OCResourceHandle m_resourceHandle; - - static AttributeMap s_attributeMap; - static std::mutex s_mutexAttributeMap; - static std::condition_variable s_conditionAttributeMap; - static bool m_isReadyAttributeMap; - - int getRepresentation(OCRepresentation &oc); - - public: - - std::string getUri(); - std::string getHostIP(); - std::string getResourceTypeName(); - std::string getResourceInterface(); - uint8_t getResourceProperty(); - OCResourceHandle getResourceHandle(); - - int setUri(std::string uri); - int setHostIP(std::string ip); - int setResourceTypeName(std::string typeName); - int setResourceInterface(std::string interface); - int setResourceProperty(uint8_t property); - int setResourceHandle(OCResourceHandle &handle); - - public: - VirtualRepresentation(); - virtual ~VirtualRepresentation(); - - std::string addVirtualTag(std::string uri); - - OCEntityHandlerResult entityHandler(const std::shared_ptr request , - const std::shared_ptr response); - void onObserve(const HeaderOptions &headerOption, const OCRepresentation &rep , - const int eCode , const int sequenceNumber); - -}; - -#endif /* VIRTUALREPRESENTATION_H_ */ diff --git a/service/notification-manager/NotificationManager/include/hosting.h b/service/notification-manager/NotificationManager/include/hosting.h index e688508..d1f2b22 100755 --- a/service/notification-manager/NotificationManager/include/hosting.h +++ b/service/notification-manager/NotificationManager/include/hosting.h @@ -28,7 +28,6 @@ // Iotivity Base CAPI #include "ocstack.h" -#include "ocsocket.h" #include "logger.h" diff --git a/service/notification-manager/NotificationManager/src/HostingHandler.cpp b/service/notification-manager/NotificationManager/src/HostingHandler.cpp deleted file mode 100644 index fc7696a..0000000 --- a/service/notification-manager/NotificationManager/src/HostingHandler.cpp +++ /dev/null @@ -1,220 +0,0 @@ -//****************************************************************** -// -// Copyright 2014 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 "HostingHandler.h" - -HostingHandler *HostingHandler::s_instance = NULL; -mutex HostingHandler::s_mutexForCreation; - -std::function< void(bool isHosting) > HostingHandler::s_findHostingCandidate; -std::function< void(std::shared_ptr< OCResource > resource) > HostingHandler::s_startHosting; -std::function< void(OCResourceHandle resourceHandle) > HostingHandler::s_notify; -std::function< void(std::string) > HostingHandler::s_addExtraStr; - -HostingHandler::HostingHandler() -{ - -} - -HostingHandler::~HostingHandler() -{ - -} - -HostingHandler *HostingHandler::getInstance() -{ - if (!s_instance) - { - s_mutexForCreation.lock(); - if (!s_instance) - { - s_instance = new HostingHandler(); - } - s_mutexForCreation.unlock(); - } - - return s_instance; -} - -void HostingHandler::initialize() -{ - // Create Hosting Handler instance - HostingHandler *ptr = HostingHandler::getInstance(); - - // Registration interface about hosting - HostingInterface hostingInterface; - - hostingInterface.setFindHosting(ptr->s_findHostingCandidate); - hostingInterface.setStartHosting(ptr->s_startHosting); - hostingInterface.setNotifyObservers(ptr->s_notify); - hostingInterface.setAddExtraStr(ptr->s_addExtraStr); - - hostingInterface.setOnFoundHostingCandidate( - std::function< void(std::shared_ptr< OCResource > resource) >( - std::bind(&HostingHandler::onFoundCandidate , HostingHandler::getInstance() , - std::placeholders::_1))); - hostingInterface.setOnObserve( - std::function< void(AttributeMap &inputAttMap, OCResourceHandle resourceHandle) >( - std::bind(&HostingHandler::onObserve , HostingHandler::getInstance() , std::placeholders::_1, - std::placeholders::_2))); - - ptr->s_addExtraStr("virtual"); - ptr->startFindHost(); -} - -void HostingHandler::initialize(HostingConfig cfg) -{ - // Create Hosting Handler instance - HostingHandler *ptr = HostingHandler::getInstance(); - - // Registration interface about hosting - HostingInterface hostingInterface; - - hostingInterface.setFindHosting(ptr->s_findHostingCandidate); - hostingInterface.setStartHosting(ptr->s_startHosting); - hostingInterface.setNotifyObservers(ptr->s_notify); - hostingInterface.setAddExtraStr(ptr->s_addExtraStr); - - hostingInterface.setOnFoundHostingCandidate( - std::function< void(std::shared_ptr< OCResource > resource) >( - std::bind(&HostingHandler::onFoundCandidate , HostingHandler::getInstance() , - std::placeholders::_1))); - hostingInterface.setOnObserve( - std::function< void(AttributeMap &inputAttMap, OCResourceHandle resourceHandle) >( - std::bind(&HostingHandler::onObserve , HostingHandler::getInstance() , std::placeholders::_1, - std::placeholders::_2))); - - // Set Hosting Config - ptr->setHostingConfig(cfg); - ptr->changeHostingMode(ptr->hostingCfg.hostingMode); - - ptr->s_addExtraStr("virtual"); - ptr->startFindHost(); -} - -void HostingHandler::setHostingConfig(HostingConfig cfg) -{ - hostingCfg.automaticMethod = cfg.automaticMethod; - hostingCfg.frequency = cfg.frequency; - hostingCfg.hostingMode = cfg.hostingMode; - hostingCfg.notifyMethod = cfg.notifyMethod; -} - -void HostingHandler::changeHostingMode(HostingMode hostingMode, AutomaticMethod autoMethod) -{ - if (hostingCfg.hostingMode != hostingMode) - { - hostingCfg.hostingMode = hostingMode; - if (hostingCfg.hostingMode == HostingMode::AutomaticMode) - { - runAutomaticHosting(autoMethod); - } - else - { - stopAutomaticHosting(); - } - } -} - -void HostingHandler::runAutomaticHosting(AutomaticMethod autoMethod) -{ - // TODO Triggering from Event Listener. - if (hostingCfg.automaticMethod != autoMethod) - { - hostingCfg.automaticMethod = autoMethod; - switch (hostingCfg.automaticMethod) - { - case AutomaticMethod::None: - break; - case AutomaticMethod::Timer: - case AutomaticMethod::DeviceStatus: - case AutomaticMethod::NetworkStatusChange: - default: - break; - } - } -} - -void HostingHandler::stopAutomaticHosting() -{ - if (hostingCfg.automaticMethod != AutomaticMethod::None) - { -// TODO - } -} - -void HostingHandler::changeAutomaticHostingMethod(AutomaticMethod autoMethod) -{ -// TODO -} -void HostingHandler::changeNotifiyMethod(NotifyMethod notifyMethod) -{ -// TODO -} -void HostingHandler::changeNotifyFrequencyType(NotifyFrequency notifyFrequency) -{ -// TODO -} - -void HostingHandler::startFindHost() -{ - if (hostingCfg.hostingMode != HostingMode::None) - { - s_findHostingCandidate(true); - } -} - -void HostingHandler::onFoundCandidate(std::shared_ptr< OCResource > resource) -{ - // TODO - // Condition of Hosting - s_startHosting(resource); -} - -void HostingHandler::onObserve(AttributeMap &AttMap, OCResourceHandle resourceHandle) -{ - - switch (hostingCfg.notifyMethod) - { - case NotifyMethod::None: - break; - case NotifyMethod::Equalization: - case NotifyMethod::Granularity: - case NotifyMethod::Frequence: - default: - notifyFrequence(resourceHandle); - break; - } -} - -void HostingHandler::notifyFrequence(OCResourceHandle resourceHandle) -{ - - switch (hostingCfg.frequency) - { - case NotifyFrequency::None: - break; - case NotifyFrequency::Periodically: - case NotifyFrequency::OnTime: - default: - s_notify(resourceHandle); - break; - } -} diff --git a/service/notification-manager/NotificationManager/src/HostingInterface.cpp b/service/notification-manager/NotificationManager/src/HostingInterface.cpp deleted file mode 100644 index 638c026..0000000 --- a/service/notification-manager/NotificationManager/src/HostingInterface.cpp +++ /dev/null @@ -1,148 +0,0 @@ -//****************************************************************** -// -// Copyright 2014 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 "HostingInterface.h" - -HostingInterface::HostingInterface() -{ - -} - -HostingInterface::~HostingInterface() -{ - // TODO Auto-generated destructor stub -} - -int HostingInterface::setOnFoundHostingCandidate( - std::function< void(std::shared_ptr< OCResource > resource) > func) -{ - if (func != NULL) - { - try - { - ResourceManager::getInstance()->m_onFoundforHosting = func; - } - catch (exception &e) - { - return false; - } - } - else - { - ResourceManager::getInstance()->m_onFoundforHosting = std::function < - void(std::shared_ptr< OCResource > resource) > ( - std::bind(&ResourceManager::onFoundforHostingDefault , ResourceManager::getInstance() , - std::placeholders::_1)); - } - - return true; -} - -int HostingInterface::setOnObserve( - std::function< void(AttributeMap &inputAttMap, OCResourceHandle resourceHandle) > func) -{ - if (func != NULL) - { - try - { - ResourceManager::getInstance()->m_onObserve = func; - } - catch (exception &e) - { - return false; - } - } - else - { - ResourceManager::getInstance()->m_onObserve = std::function < - void(AttributeMap & inputAttMap, OCResourceHandle resourceHandle) > ( - std::bind(&ResourceManager::onObserveDefault , ResourceManager::getInstance() , - std::placeholders::_1, std::placeholders::_2)); - } - - return true; -} - -int HostingInterface::setNotifyObservers(std::function< void(OCResourceHandle resourceHandle) > - &func) -{ - try - { - func = std::function< void(OCResourceHandle resourceHandle) >( - std::bind(&ResourceManager::notifyObservers , ResourceManager::getInstance() , - std::placeholders::_1)); - } - catch (exception &e) - { - return false; - } - - return true; -} - -int HostingInterface::setStartHosting( - std::function< void(std::shared_ptr< OCResource > resource) > &func) -{ - try - { - func = std::function< void(std::shared_ptr< OCResource > resource) >( - std::bind(&ResourceManager::startHosting , ResourceManager::getInstance() , - std::placeholders::_1)); - } - catch (exception &e) - { - return false; - } - - return true; -} - -int HostingInterface::setFindHosting(std::function< void(bool isHosting) > &func) -{ - try - { - func = std::function< void(bool isHosting) >( - std::bind(&ResourceManager::findNMResource , - ResourceManager::getInstance() , - std::placeholders::_1)); - } - catch (exception &e) - { - return false; - } - - return true; -} - -int HostingInterface::setAddExtraStr(std::function< void(std::string) > &func) -{ - try - { - func = std::function< void(std::string str) >( - std::bind(&ResourceManager::addExtraStr , ResourceManager::getInstance() , - std::placeholders::_1)); - } - catch (exception &e) - { - return false; - } - - return true; -} diff --git a/service/notification-manager/NotificationManager/src/NotificationManager.cpp b/service/notification-manager/NotificationManager/src/NotificationManager.cpp deleted file mode 100644 index 8f1d391..0000000 --- a/service/notification-manager/NotificationManager/src/NotificationManager.cpp +++ /dev/null @@ -1,162 +0,0 @@ -//****************************************************************** -// -// Copyright 2014 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 "NotificationManager.h" - -NotificationManager *NotificationManager::s_instance = NULL; -mutex NotificationManager::s_mutexForCreation; - -NotificationManager::NotificationManager() -{ - -} - -NotificationManager::NotificationManager(HostingConfig cfg) -{ - -} - -NotificationManager::~NotificationManager() -{ - -} - -void NotificationManager::initialize() -{ - // find local ip address - std::string ipAddress; - NotificationManager::getInstance()->scanAndGetNetworkInterface(ipAddress); - - // set ip address - OICPlatformConfig::getInstance()->setIP(ipAddress); - - // initialize hosting handler - HostingHandler::initialize(); -} - -void NotificationManager::initialize(HostingConfig cfg) -{ - // find local ip address - std::string ipAddress; - NotificationManager::getInstance()->scanAndGetNetworkInterface(ipAddress); - - // set ip address - OICPlatformConfig::getInstance()->setIP(ipAddress); - - // initialize hosting handler - HostingHandler::initialize(cfg); -} - -void NotificationManager::registerHostingEventListener() -{ - // TODO : Initial HostingEventListener (v1.0) -} - -NotificationManager *NotificationManager::getInstance() -{ - if (!s_instance) - { - s_mutexForCreation.lock(); - if (!s_instance) - { - s_instance = new NotificationManager(); - } - s_mutexForCreation.unlock(); - } - - return s_instance; -} - -int NotificationManager::getNetInfo(IN int &sck, IN struct ifreq *item, OUT std::string &ip_addres) -{ - struct ifreq temp_ifr; - memset(&temp_ifr, 0, sizeof(temp_ifr)); - strcpy(temp_ifr.ifr_name, item->ifr_name); - - if (ioctl(sck, SIOCGIFFLAGS, &temp_ifr)) - { - return -1; - } - - if (!((temp_ifr.ifr_flags & IFF_UP) && (temp_ifr.ifr_flags & IFF_RUNNING))) - { - return -1; - } - - std::string ip(inet_ntoa(((struct sockaddr_in *) &item->ifr_addr)->sin_addr)); - if (ip.empty()) - { - return -1; - } - - if (ip.find("127.0.0") == 0) - { - return -1; - } - - ip_addres = ip; - return 0; -} - -bool NotificationManager::scanAndGetNetworkInterface(OUT std::string &ip_addres) -{ - while (1) - { - char buf[1024] = { 0, }; - struct ifconf ifc; - struct ifreq *ifr; - int sck; - int interfaces; - int i; - - sck = socket(AF_INET, SOCK_DGRAM, 0); - if (sck < 0) - { - usleep(10); - continue; - } - - ifc.ifc_len = sizeof(buf); - ifc.ifc_buf = buf; - if (ioctl(sck, SIOCGIFCONF, &ifc) < 0) - { - printf( "SIOCGIFCONF Failed "); - close(sck); - usleep(10); - continue; - } - - ifr = ifc.ifc_req; - interfaces = ifc.ifc_len / sizeof(struct ifreq); - - for (i = 0; i < interfaces; i++) - { - if ( getNetInfo(sck, &ifr[i], ip_addres) == 0 ) - { - return 0; - } - continue; - } - close(sck); - usleep(10); - } - - return 0; -} diff --git a/service/notification-manager/NotificationManager/src/OICPlatformConfig.cpp b/service/notification-manager/NotificationManager/src/OICPlatformConfig.cpp deleted file mode 100644 index 0dd4ed5..0000000 --- a/service/notification-manager/NotificationManager/src/OICPlatformConfig.cpp +++ /dev/null @@ -1,80 +0,0 @@ -//****************************************************************** -// -// Copyright 2014 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 "OICPlatformConfig.h" - - -OICPlatformConfig *OICPlatformConfig::s_instance = NULL; -mutex OICPlatformConfig::s_mutexForCreation; -//OCPlatform *OICPlatformConfig::s_nmOCPlatform = NULL; -PlatformConfig OICPlatformConfig::s_cfg; -//(ServiceType::InProc, ModeType::Both,"", 5683, QualityOfService::NonConfirmable); - -OICPlatformConfig::OICPlatformConfig() -{ - // TODO Auto-generated constructor stub - -} - -OICPlatformConfig::~OICPlatformConfig() -{ - // TODO Auto-generated destructor stub -} - - -OICPlatformConfig *OICPlatformConfig::getInstance() -{ - if (!s_instance) - { - s_mutexForCreation.lock(); - if (!s_instance) - { - s_instance = new OICPlatformConfig(); - Configure(s_cfg); - } - s_mutexForCreation.unlock(); - } - - return s_instance; -} - -//void OICPlatformConfig::getOCPlatform() -//{ -//// if(!s_nmOCPlatform) -//// { -//// if(s_cfg.ipAddress.empty()) -//// { -//// return NULL; -//// } -//// s_nmOCPlatform = new OCPlatform(s_cfg); -//// Configure(s_cfg); -//// } -//// return s_nmOCPlatform; -//} - -void OICPlatformConfig::initialize() -{ - -} - -void OICPlatformConfig::setIP(std::string ipaddress) -{ - s_cfg.ipAddress = ipaddress; -} diff --git a/service/notification-manager/NotificationManager/src/RegistrationManager.cpp b/service/notification-manager/NotificationManager/src/RegistrationManager.cpp deleted file mode 100644 index c019b6b..0000000 --- a/service/notification-manager/NotificationManager/src/RegistrationManager.cpp +++ /dev/null @@ -1,109 +0,0 @@ -//****************************************************************** -// -// Copyright 2014 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 "RegistrationManager.h" - -RegistrationManager *RegistrationManager::s_instance = NULL; -mutex RegistrationManager::s_mutexForCreation; - -RegistrationManager::RegistrationManager() -{ -} - -RegistrationManager::~RegistrationManager() -{ -} - -RegistrationManager *RegistrationManager::getInstance() -{ - if (!s_instance) - { - s_mutexForCreation.lock(); - if (s_instance) - { - s_instance = new RegistrationManager(); - } - s_mutexForCreation.unlock(); - } - - return s_instance; -} - -int RegistrationManager::addResource() -{ - return 0; -} - -int RegistrationManager::removeResource() -{ - return 0; -} - -int RegistrationManager::updateResource() -{ - return 0; -} - -bool RegistrationManager::registerNMResource(VirtualRepresentation &resourceObject , - std::shared_ptr< OCResource > resource) -{ - std::string uri = resourceObject.getUri(); - std::string type = resourceObject.getResourceTypeName(); - std::string interface = resourceObject.getResourceInterface(); - - OCResourceHandle resourceHandle; - - OCStackResult result; - result = registerResource(resourceHandle , uri , type , - interface , - std::function < - OCEntityHandlerResult(const std::shared_ptr< OCResourceRequest > request , - const std::shared_ptr< OCResourceResponse > response) > ( - std::bind(&VirtualRepresentation::entityHandler , resourceObject , - std::placeholders::_1 , std::placeholders::_2)) , - resourceObject.getResourceProperty()); - - resourceObject.setResourceHandle(resourceHandle); - - if (OC_STACK_OK != result) - { - return false; - } - else - { - QueryParamsMap queryParmaMap; - resource->observe(ObserveType::Observe , queryParmaMap , - std::function < - void(const HeaderOptions headerOption, - const OCRepresentation & rep , const int &eCode , - const int &sequenceNumber) > ( - std::bind(&VirtualRepresentation::onObserve , resourceObject , - std::placeholders::_1 , std::placeholders::_2 , - std::placeholders::_3 , std::placeholders::_4))); - } - - return true; -} - -bool RegistrationManager::unregisterResource() -{ - return true; -} - diff --git a/service/notification-manager/NotificationManager/src/ResourceManager.cpp b/service/notification-manager/NotificationManager/src/ResourceManager.cpp deleted file mode 100644 index 8e35655..0000000 --- a/service/notification-manager/NotificationManager/src/ResourceManager.cpp +++ /dev/null @@ -1,232 +0,0 @@ -//****************************************************************** -// -// Copyright 2014 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 "ResourceManager.h" - -ResourceManager *ResourceManager::s_instance = NULL; -mutex ResourceManager::s_mutexForCreation; -std::list< VirtualRepresentation > ResourceManager::s_resourceList; - -std::string ResourceManager::s_extraStr; - -ResourceManager::ResourceManager() -{ - m_onFoundforHosting = NULL; - m_onObserve = NULL; - m_notify = NULL; -} - -ResourceManager::~ResourceManager() -{ -} - -ResourceManager *ResourceManager::getInstance() -{ - if (!s_instance) - { - s_mutexForCreation.lock(); - if (!s_instance) - { - s_instance = new ResourceManager(); - } - s_mutexForCreation.unlock(); - } - return s_instance; -} - -VirtualRepresentation ResourceManager::findVirtualRepresentation(std::string uri) -{ - - VirtualRepresentation retObject; - - for (auto it = s_resourceList.begin() ; it != s_resourceList.end() ; it++) - { - if (it->getUri().compare(uri) == 0) - { - retObject = *it; - return retObject; - } - } - - return retObject; -} - -void ResourceManager::findNMResource(bool isHosting) -{ - if (isHosting) - { - findResource("" , "coap://224.0.1.187/oc/core", - std::function< void(std::shared_ptr< OCResource > resource) >( - std::bind(&ResourceManager::foundResourceforhosting , ResourceManager::getInstance() , - std::placeholders::_1))); - } -} - -void ResourceManager::foundResourceforhosting(std::shared_ptr< OCResource > resource) -{ - try - { - if (resource) - { - if (resource->uri().find("/a/NM") != std::string::npos) - { - ResourceManager::getInstance()->m_onFoundforHosting(resource); - } - } - else - { - // TODO - } - - } - catch (std::exception &e) - { - } -} - -void ResourceManager::startHosting(std::shared_ptr< OCResource > resource) -{ - - cout << "start hosting" << endl; - VirtualRepresentation tmp = findVirtualRepresentation( resource->uri() ); - - if ( !tmp.getUri().empty() ) - { - return; - } - - VirtualRepresentation resourceObject; - resourceObject.setUri(resource->uri()); - - std::cout << "resourceObject uri: " << resourceObject.getUri() << std::endl; - - std::string resourceHostIP; - std::string resourceType; - std::string resourceInterface; - uint8_t resourceProperty; - - resourceHostIP = resource->host(); - resourceType = *(resource->getResourceTypes().data()); - resourceInterface = *(resource->getResourceInterfaces().data()); - resourceProperty = (OC_DISCOVERABLE | resource->isObservable()); - - resourceObject.setHostIP(resourceHostIP); - resourceObject.setResourceTypeName(resourceType); - resourceObject.setResourceInterface(resourceInterface); - resourceObject.setResourceProperty(resourceProperty); - - RegistrationManager::getInstance()->registerNMResource(resourceObject , resource); - - s_resourceList.push_back(resourceObject); - -} - -void ResourceManager::notifyObservers(OCResourceHandle resourceHandle) -{ - OCStackResult result = OC_STACK_OK; - - result = notifyAllObservers(resourceHandle); - - if (OC_STACK_NO_OBSERVERS == result) - { - // No observers. - // TODO - } -} - -AttributeMap ResourceManager::copyAttributeMap(AttributeMap &inputAttMap) -{ - - AttributeMap retAttMap; - - retAttMap = inputAttMap; -// for(auto it = inputAttMap.begin() ; it != inputAttMap.end() ; ++it) -// { -// AttributeValues tmpVal; -// -// for(auto valueItr = it->second.begin() ; valueItr != it->second.end() ; ++valueItr) -// { -// std::string tmpStr; -// -// tmpStr.append(*valueItr); -// -// tmpVal.push_back(tmpStr); -// } -// retAttMap[it->first] = tmpVal; -// -// } - return retAttMap; -} - -bool ResourceManager::isEmptyAttributeMap(AttributeMap &inputAttMap) -{ - for (auto it = inputAttMap.begin() ; it != inputAttMap.end() ; ++it) - { - if (inputAttMap.find(it->first) == inputAttMap.end()) - { - return true; - } - } - return false; -} - -void ResourceManager::onFoundforHostingDefault(std::shared_ptr< OCResource > resource) -{ - ResourceManager::getInstance()->startHosting(resource); -} -void ResourceManager::onObserveDefault(AttributeMap &inputAttMap , OCResourceHandle resourceHandle) -{ - ResourceManager::getInstance()->notifyObservers(resourceHandle); -} - -void ResourceManager::printAttributeMap(AttributeMap &inputAttMap) -{ - for (auto it = inputAttMap.begin() ; it != inputAttMap.end() ; ++it) - { - std::cout << "\tAttribute name: " << it->first << " value: "; - - for (auto valueItr = it->second.begin() ; valueItr != it->second.end() ; ++valueItr) - { - std::cout << "\t" << *valueItr << " "; - } - - std::cout << std::endl; - } -} - -void ResourceManager::addExtraStr(std::string str) -{ - s_extraStr = str; -} - -std::string ResourceManager::getExtraStr() -{ - return s_extraStr; -} - -void ResourceManager::checkResourceDBPolicy() -{ - -} - -void ResourceManager::saveResourceDB() -{ - -} diff --git a/service/notification-manager/NotificationManager/src/VirtualRepresentation.cpp b/service/notification-manager/NotificationManager/src/VirtualRepresentation.cpp deleted file mode 100644 index 313d61f..0000000 --- a/service/notification-manager/NotificationManager/src/VirtualRepresentation.cpp +++ /dev/null @@ -1,231 +0,0 @@ -//****************************************************************** -// -// Copyright 2014 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 "VirtualRepresentation.h" - -AttributeMap VirtualRepresentation::s_attributeMap; - -std::mutex VirtualRepresentation::s_mutexAttributeMap; -std::condition_variable VirtualRepresentation::s_conditionAttributeMap; -bool VirtualRepresentation::m_isReadyAttributeMap = true; - -int g_num = 0; - -VirtualRepresentation::VirtualRepresentation() -{ - m_resourceHandle = NULL; - m_resourceProperty = 0x00; -} - -VirtualRepresentation::~VirtualRepresentation() -{ -} - -std::string VirtualRepresentation::addVirtualTag(std::string uri) -{ - std::string ret = uri; - return ret.append(VIRTURL_TAG + std::to_string(g_num++)); -} - -OCResourceHandle VirtualRepresentation::getResourceHandle() -{ - return m_resourceHandle; -} - -std::string VirtualRepresentation::getUri() -{ - return m_virtualUri; -} - -std::string VirtualRepresentation::getHostIP() -{ - return m_originHostIP; -} - -std::string VirtualRepresentation::getResourceTypeName() -{ - return m_resourceTypeName; -} - -std::string VirtualRepresentation::getResourceInterface() -{ - return m_resourceInterface; -} - -uint8_t VirtualRepresentation::getResourceProperty() -{ - return m_resourceProperty; -} - -int VirtualRepresentation::setUri(std::string uri) -{ - m_virtualUri = addVirtualTag(uri); - return true; -} - -int VirtualRepresentation::setHostIP(std::string ip) -{ - m_originHostIP = ip; - return true; -} - -int VirtualRepresentation::setResourceTypeName(std::string typeName) -{ - m_resourceTypeName = typeName; - return true; -} - -int VirtualRepresentation::setResourceInterface(std::string interface) -{ - m_resourceInterface = interface; - return true; -} - -int VirtualRepresentation::setResourceProperty(uint8_t property) -{ - m_resourceProperty = property; - return true; -} - -int VirtualRepresentation::setResourceHandle(OCResourceHandle &handle) -{ - m_resourceHandle = handle; - return true; -} - -int VirtualRepresentation::getRepresentation(OCRepresentation &oc) -{ - oc.setAttributeMap(s_attributeMap); - oc.setUri(this->getUri().c_str()); - return true; -} - -OCEntityHandlerResult VirtualRepresentation::entityHandler(const std::shared_ptr - request , const std::shared_ptr response) -{ - if (request) - { - std::string requestType = request->getRequestType(); - int requestFlag = request->getRequestHandlerFlag(); - - if (requestFlag == RequestHandlerFlag::InitFlag) - { - } - - else if (requestFlag == RequestHandlerFlag::RequestFlag) - { - if ( (requestType == "GET") && response ) - { - - std::unique_lock< std::mutex > lck(s_mutexAttributeMap); - while (!m_isReadyAttributeMap) - { - s_conditionAttributeMap.wait(lck); - } - m_isReadyAttributeMap = false; - - OCRepresentation rep; - getRepresentation(rep); - - response->setErrorCode(200); - response->setResourceRepresentation(rep , DEFAULT_INTERFACE); - - m_isReadyAttributeMap = true; - s_conditionAttributeMap.notify_all(); - } - else if (requestType == "PUT") - { - // TODO - } - else if (requestType == "POST") - { - // TODO - } - else if (requestType == "DELETE") - { - // TODO - } - else - { - // TODO - } - } - else if (requestFlag == RequestHandlerFlag::InitFlag) - { - // TODO - } - else if (requestFlag == RequestHandlerFlag::ObserverFlag) - { - // TODO - cout << "requestFlag == RequestHandlerFlag::ObserverFlag\n"; - } - else - { - // requestFlag is not [Request, Init, Observer] - // TODO - } - } - else - { - // Param(request) is empty. - // TODO - } - return OC_EH_OK; -} - -void VirtualRepresentation::onObserve(const HeaderOptions &headerOption, - const OCRepresentation &rep , const int eCode , const int sequenceNumber) -{ - if (eCode == SUCCESS_RESPONSE) - { - AttributeMap inputAttributeMap = rep.getAttributeMap(); - if (ResourceManager::getInstance()->isEmptyAttributeMap(inputAttributeMap)) - { - return; - } - VirtualRepresentation tmpObj = *this; - if (!tmpObj.getUri().empty()) - { - AttributeMap tmpAttMap = ResourceManager::getInstance()->copyAttributeMap(inputAttributeMap); - { - std::unique_lock< std::mutex > lck(s_mutexAttributeMap); - while (!m_isReadyAttributeMap) - { - s_conditionAttributeMap.wait(lck); - } - m_isReadyAttributeMap = false; - s_attributeMap = tmpAttMap; - m_isReadyAttributeMap = true; - s_conditionAttributeMap.notify_all(); - } - - if (ResourceManager::getInstance()->m_onObserve) - { - ResourceManager::getInstance()->m_onObserve(inputAttributeMap, tmpObj.getResourceHandle()); - } - } - } - else - { - // Check the error. - // TODO - } - cout << "VirtualRepresentation::onObserve Out\n"; -} diff --git a/service/notification-manager/NotificationManager/src/hosting.c b/service/notification-manager/NotificationManager/src/hosting.c index c614ee0..6539b08 100755 --- a/service/notification-manager/NotificationManager/src/hosting.c +++ b/service/notification-manager/NotificationManager/src/hosting.c @@ -352,7 +352,6 @@ OCStackResult OICStartCoordinate() s_mirrorResourceList = createMirrorResourceList(); s_requestHandleList = createRequestHandleList(); result = requestPresence(OC_DEFAULT_ADDRESS); - if(result != OC_STACK_OK) { return OC_STACK_ERROR; @@ -395,8 +394,8 @@ int requestCoordinateeCandidateDiscovery(char *sourceResourceAddress) cbData.context = (void *)DEFAULT_CONTEXT_VALUE; cbData.cd = NULL; - result = OCDoResource(&handle, OC_REST_GET, queryUri, OIC_COORDINATING_FLAG, 0, OC_LOW_QOS, &cbData, - NULL, 0); + result = OCDoResource(&handle, OC_REST_GET, queryUri, OIC_COORDINATING_FLAG, 0, + OC_ETHERNET, OC_LOW_QOS, &cbData, NULL, 0); if (result != OC_STACK_OK) { OC_LOG_V(DEBUG, HOSTING_TAG, "OCStack resource error"); @@ -426,7 +425,7 @@ OCStackResult requestPresence(char *sourceResourceAddress) sprintf(queryUri, "coap://%s%s", sourceResourceAddress , OC_PRESENCE_URI); OC_LOG_V(DEBUG, HOSTING_TAG, "initializePresenceForCoordinating Query : %s", queryUri); - result = OCDoResource(&handle, OC_REST_PRESENCE, queryUri, 0, 0, OC_LOW_QOS, &cbData, NULL, 0); + result = OCDoResource(&handle, OC_REST_PRESENCE, queryUri, 0, 0, OC_ETHERNET, OC_LOW_QOS, &cbData, NULL, 0); if (result != OC_STACK_OK) { @@ -756,7 +755,7 @@ OCStackResult requestResourceObservation(MirrorResource *mirrorResource) OIC_COORDINATING_FLAG); result = OCDoResource(&mirrorResource->resourceHandle[OIC_REQUEST_HANDLE], OC_REST_OBSERVE, query, - 0, NULL, + 0, NULL, OC_ETHERNET, OC_HIGH_QOS, &cbData, NULL, 0); if (result != OC_STACK_OK) @@ -1308,11 +1307,11 @@ OCStackResult requestQuery(RequestHandle *request, OCMethod method, ((OCEntityHandlerRequest*)request->requestHandle[OIC_REQUEST_BY_CLIENT])->reqJSONPayload); result = OCDoResource(&request->requestHandle[OIC_REQUEST_BY_COORDINATOR], - method, queryFullUri, NULL, payload, OC_LOW_QOS, &cbData, NULL, 0); + method, queryFullUri, NULL, payload, OC_ETHERNET, OC_LOW_QOS, &cbData, NULL, 0); } else{ result = OCDoResource(&request->requestHandle[OIC_REQUEST_BY_COORDINATOR], - method, queryFullUri, NULL, 0, OC_LOW_QOS, &cbData, NULL, 0); + method, queryFullUri, NULL, 0, OC_ETHERNET, OC_LOW_QOS, &cbData, NULL, 0); } if (result != OC_STACK_OK) diff --git a/service/notification-manager/NotificationManager/src/linux/main.cpp b/service/notification-manager/NotificationManager/src/linux/main.cpp deleted file mode 100644 index 473b366..0000000 --- a/service/notification-manager/NotificationManager/src/linux/main.cpp +++ /dev/null @@ -1,66 +0,0 @@ -//****************************************************************** -// -// Copyright 2014 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 -#include "NotificationManager.h" - -using namespace OC; - -int main(void) -{ - - std::cout << endl; - std::cout << "========================================================" << endl; - std::cout << "Start Notification Manager : Hosting v0.5\n"; - - - HostingConfig cfg; - cfg.hostingMode = HostingMode::ManualMode; - cfg.automaticMethod = AutomaticMethod::None; - cfg.notifyMethod = NotifyMethod::Frequence; - cfg.frequency = NotifyFrequency::OnTime; - - NotificationManager::initialize(cfg); - - while (true) - { - char signal; - cin >> signal; - - switch (signal) - { - case 'q': - case 'Q': - std::cout << endl; - std::cout << "========================================================" << endl; - std::cout << "End Notification Manager : Hosting v0.5\n"; - return true; - default: - break; - } - - } - - std::cout << endl; - std::cout << "========================================================" << endl; - std::cout << "End Notification Manager : Hosting v0.5\n"; - - return true; -} diff --git a/service/notification-manager/NotificationManager/src/virtualResource.c b/service/notification-manager/NotificationManager/src/virtualResource.c old mode 100644 new mode 100755 diff --git a/service/notification-manager/NotificationManager/src/virtualResource.h b/service/notification-manager/NotificationManager/src/virtualResource.h index b08138a..44885ab 100755 --- a/service/notification-manager/NotificationManager/src/virtualResource.h +++ b/service/notification-manager/NotificationManager/src/virtualResource.h @@ -26,7 +26,6 @@ #include #include "ocstack.h" -#include "ocsocket.h" #include "logger.h" #include "cJSON.h" diff --git a/service/notification-manager/SConscript b/service/notification-manager/SConscript old mode 100644 new mode 100755 index ac154f6..09123fa --- a/service/notification-manager/SConscript +++ b/service/notification-manager/SConscript @@ -29,6 +29,8 @@ if env.get('RELEASE'): env.AppendUnique(CPPDEFINES = ['NDEBUG']) else: env.AppendUnique(CCFLAGS = ['-g']) + +if env.get('LOGGING'): env.AppendUnique(CPPDEFINES = ['-DTB_LOG']) lib_env = env.Clone() @@ -42,7 +44,7 @@ target_os = env.get('TARGET_OS') notimgr_env.AppendUnique(CPPPATH = ['NotificationManager/include']) notimgr_env.AppendUnique(CPPPATH = ['../../extlibs/cjson']) notimgr_env.AppendUnique(CPPPATH = ['../../resource/csdk/logger/include']) -notimgr_env.PrependUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'coap']) +notimgr_env.PrependUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'connectivity_abstraction', 'libcoap']) if target_os not in ['windows', 'winrt']: notimgr_env.AppendUnique(CXXFLAGS = ['-O2', '-g', '-Wall', '-fmessage-length=0']) diff --git a/service/notification-manager/SampleApp/linux/SConscript b/service/notification-manager/SampleApp/linux/SConscript old mode 100644 new mode 100755 index f21d4aa..74dd166 --- a/service/notification-manager/SampleApp/linux/SConscript +++ b/service/notification-manager/SampleApp/linux/SConscript @@ -1,23 +1,3 @@ -#****************************************************************** -# -# Copyright 2014 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. -# -#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - ## # NotificationManager build script ## @@ -32,12 +12,35 @@ notimgr_env = lib_env.Clone() # Build flags ###################################################################### notimgr_env.AppendUnique(CPPPATH = ['../../NotificationManager/include']) -notimgr_env.AppendUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'coap', 'pthread']) +notimgr_env.AppendUnique(CPPPATH = ['../../../../extlibs/cjson']) +notimgr_env.AppendUnique(CPPPATH = ['../../../../resource/csdk/connectivity/api']) notimgr_env.AppendUnique(CXXFLAGS = ['-O2', '-g', '-Wall', '-fmessage-length=0', '-std=c++0x']) +notimgr_c_env = notimgr_env.Clone() +notimgr_env.AppendUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'connectivity_abstraction', 'coap', 'pthread']) +notimgr_c_env.AppendUnique(LIBS = ['octbstack', 'oc_logger', 'connectivity_abstraction', 'coap', 'pthread','NOTISDKLibrary']) -###################################################################### +if env.get('SECURED') == '1': + notimgr_env.AppendUnique(LIBS = ['tinydtls']) +notimgr_env.ParseConfig('pkg-config --libs glib-2.0') +notimgr_env.ParseConfig('pkg-config --cflags glib-2.0') +if 'rt' in notimgr_env.get('LIBS'): + notimgr_env.Append(LIBS = ['rt']) + +if env.get('SECURED') == '1': + notimgr_c_env.AppendUnique(LIBS = ['tinydtls']) +notimgr_c_env.ParseConfig('pkg-config --libs glib-2.0') +notimgr_c_env.ParseConfig('pkg-config --cflags glib-2.0') +if 'rt' in notimgr_c_env.get('LIBS'): + notimgr_c_env.Append(LIBS = ['rt']) + +#################################################################### # Source files and Targets ###################################################################### sampleprovider = notimgr_env.Program('sampleprovider', 'sampleProvider/SampleProvider.cpp') sampleconsumer = notimgr_env.Program('sampleconsumer', 'sampleConsumer/SampleConsumer.cpp') +notificationmanager = notimgr_c_env.Program('notificationmanager', 'notificationManager/main.c') + +#notimgr_env.InstallTarget(sampleprovider, 'sampleprovider') +#notimgr_env.InstallTarget(sampleconsumer, 'sampleconsumer') +#notimgr_env.InstallTarget(notificationmanager, 'notificationmanager') diff --git a/service/notification-manager/SampleApp/linux/notificationManager/main.c b/service/notification-manager/SampleApp/linux/notificationManager/main.c old mode 100644 new mode 100755 index 8948a74..9340681 --- a/service/notification-manager/SampleApp/linux/notificationManager/main.c +++ b/service/notification-manager/SampleApp/linux/notificationManager/main.c @@ -33,21 +33,9 @@ void handleSigInt(int signum); */ int main() { - - uint8_t interfaceAddress[20] = {0}; - uint8_t *coordinatingAddress = NULL; - uint8_t interfaceName[] = "eth0"; - printf("OCResourceHosting is starting...\n"); - if ( OCGetInterfaceAddress(interfaceName, sizeof(interfaceName), AF_INET, interfaceAddress, - sizeof(interfaceAddress)) == OC_ERR_SUCCESS) - { - printf("Starting OIC resource hosting on address %s\n", interfaceAddress); - coordinatingAddress = interfaceAddress; - } - - if (OCInit((char *) coordinatingAddress, USE_RANDOM_PORT, OC_CLIENT_SERVER) != OC_STACK_OK) + if (OCInit((char *) NULL, 0, OC_CLIENT_SERVER) != OC_STACK_OK) { printf("OCStack init error\n"); return 0; diff --git a/service/notification-manager/SampleApp/linux/sampleConsumer/SampleConsumer.cpp b/service/notification-manager/SampleApp/linux/sampleConsumer/SampleConsumer.cpp old mode 100644 new mode 100755 index 74b8180..08dc41a --- a/service/notification-manager/SampleApp/linux/sampleConsumer/SampleConsumer.cpp +++ b/service/notification-manager/SampleApp/linux/sampleConsumer/SampleConsumer.cpp @@ -1,6 +1,6 @@ //****************************************************************** // -// Copyright 2014 Samsung Electronics All Rights Reserved. +// Copyright 2015 Samsung Electronics All Rights Reserved. // //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // @@ -26,38 +26,33 @@ #include #include "OCPlatform.h" #include "OCApi.h" - +#include using namespace OC; const int SUCCESS_RESPONSE = OC_STACK_OK; -static ObserveType OBSERVE_TYPE_TO_USE = ObserveType::Observe; -std::shared_ptr< OCResource > g_curResource; +#define OBSERVE 1 +#define GET 2 +#define PUT 3 +#define DELETE 4 +std::shared_ptr< OCResource > g_curResource; +std::mutex curResourceLock; OCStackResult nmfindResource(const std::string &host , const std::string &resourceName); void onObserve(const HeaderOptions &headerOption , const OCRepresentation &rep , const int &eCode, const int &sequenceNumber); +void onPut(const HeaderOptions &headerOption, const OCRepresentation &rep, const int eCode); +void onGet(const HeaderOptions &headerOption , const OCRepresentation &rep , const int eCode); +void onDelete(const HeaderOptions &headerOption , const int eCode); + + void findResourceCandidate() { try { - nmfindResource("" , "coap://224.0.1.187/oc/core?rt=NotificationManager.Hosting"); + nmfindResource("" , "coap://224.0.1.187/oc/core?rt=Resource.Hosting"); std::cout << "Finding Resource... " << std::endl; - while (true) - { - char signal; - cin >> signal; - - switch (signal) - { - case 'q': - case 'Q': - exit(-1); - default: - break; - } - } } catch (OCException &e) @@ -67,10 +62,61 @@ void findResourceCandidate() void startObserve(std::shared_ptr< OCResource > resource) { + if (resource == NULL) + { + std::cout << "startObserve() error : resource == null" << std::endl; + return; + } + + QueryParamsMap test; + if (OC_STACK_OK != resource->observe(ObserveType::Observe , test , &onObserve)) + std::cout << "To Fail resource observe() process" << std::endl; +} + +void startGet(std::shared_ptr< OCResource > resource) +{ + + if (resource == NULL) + { + std::cout << "startObserve() error : resource == null" << std::endl; + return; + } + + QueryParamsMap test; + std::cout << "URI :" << resource->uri() << std::endl; + if (OC_STACK_OK != resource->get(test, &onGet)) + std::cout << "To Fail resource get() process" << std::endl; +} + +void startPut(std::shared_ptr< OCResource > resource) +{ + if (resource == NULL) + { + std::cout << "startObserve() error : resource == null" << std::endl; + return; + } + g_curResource = resource; + OCRepresentation rep; + rep.setValue("temperature", 25); + rep.setValue("humidity", 10); QueryParamsMap test; - resource->observe(ObserveType::Observe , test , &onObserve); + if (OC_STACK_OK != resource->put(rep, test, &onPut)) + std::cout << "To Fail resource put() process" << std::endl; +} + +void startDelete(std::shared_ptr< OCResource > resource) +{ + if (resource == NULL) + { + std::cout << "startObserve() error : resource == null" << std::endl; + return; + } + + g_curResource = resource; + if (OC_STACK_OK != resource->deleteResource(&onDelete)) + std::cout << "To Fail resource delete() process" << std::endl; } int observe_count() @@ -83,40 +129,16 @@ void onObserve(const HeaderOptions &headerOption , const OCRepresentation &rep , const int &sequenceNumber) { std::cout << "onObserve" << std::endl; -// if(eCode == SUCCESS_RESPONSE) - if (eCode <= OC_STACK_RESOURCE_DELETED) - { - - AttributeMap attributeMap = rep.getAttributeMap(); - - for (auto it = attributeMap.begin() ; it != attributeMap.end() ; ++it) - { - if (attributeMap.find(it->first) == attributeMap.end()) - { - return; - } - } - - if (rep.getUri().empty()) - { - cout << "uri is null\n"; - return; - } + if (eCode <= OC_STACK_OK) + { std::cout << std::endl; std::cout << "========================================================" << std::endl; std::cout << "Receive OBSERVE RESULT:" << std::endl; + std::cout << "\tUri: " << rep.getUri() << std::endl; std::cout << "\tSequenceNumber: " << sequenceNumber << std::endl; - for (auto it = attributeMap.begin() ; it != attributeMap.end() ; ++it) - { - std::cout << "\tAttribute name: " << it->first << " value: "; - for (auto valueItr = it->second.begin() ; valueItr != it->second.end() ; ++valueItr) - { - std::cout << "\t" << *valueItr << " "; - } - - std::cout << std::endl; - } + std::cout << "\tTemperature : " << rep.getValue("temperature") << std::endl; + std::cout << "\tHumidity : " << rep.getValue("humidity") << std::endl; if (observe_count() > 30) { @@ -140,12 +162,16 @@ void foundResource(std::shared_ptr< OCResource > resource) { std::string resourceURI; std::string hostAddress; + + std::cout << "foundResource" << std::endl; + try { + std::cout << "mutex lock passed" << std::endl; if (resource) { -// if(resource->uri().find("/a/NM/TempHumSensor/virtual") != std::string::npos) - if (resource->uri().find("/a/NM/TempHumSensor") != std::string::npos) + std::cout << resource->uri() << std::endl; + if (resource->uri() == "/a/TempHumSensor") { std::cout << std::endl; std::cout << "========================================================" << std::endl; @@ -157,7 +183,7 @@ void foundResource(std::shared_ptr< OCResource > resource) hostAddress = resource->host(); std::cout << "\tHost address of the resource: " << hostAddress << std::endl; - startObserve(resource); + g_curResource = resource; } } else @@ -173,7 +199,7 @@ void foundResource(std::shared_ptr< OCResource > resource) OCStackResult nmfindResource(const std::string &host , const std::string &resourceName) { - return OCPlatform::findResource(host , resourceName , &foundResource); + return OCPlatform::findResource(host , resourceName , OC_ETHERNET, &foundResource); } void getRepresentation(std::shared_ptr< OCResource > resource) @@ -184,101 +210,65 @@ void getRepresentation(std::shared_ptr< OCResource > resource) } } -void onPut(const OCRepresentation &rep , const int eCode) +void onPut(const HeaderOptions &headerOption, const OCRepresentation &rep, const int eCode) { - if (eCode == SUCCESS_RESPONSE) + try { - std::cout << "PUT request was successful" << std::endl; + if (eCode == OC_STACK_OK) + { + std::cout << "PUT request was successful" << std::endl; + int humidity; + int temperature; + rep.getValue("temperature", temperature); + rep.getValue("humidity", humidity); - AttributeMap attributeMap = rep.getAttributeMap(); - for (auto it = attributeMap.begin() ; it != attributeMap.end() ; ++it) + std::cout << "\t temperature: " << temperature << std::endl; + std::cout << "\t humidity: " << humidity << std::endl; + } + else { - std::cout << "\tAttribute name: " << it->first << " value: "; - for (auto valueItr = it->second.begin() ; valueItr != it->second.end() ; ++valueItr) - { - std::cout << "\t" << *valueItr << " "; - } - - std::cout << std::endl; + std::cout << "onPut Response error: " << eCode << std::endl; + std::exit(-1); } + } + catch (std::exception &e) + { + std::cout << "Exception: " << e.what() << " in onPut" << std::endl; + } +} - std::vector< OCRepresentation > children = rep.getChildren(); - - for (auto oit = children.begin() ; oit != children.end() ; ++oit) +//callback hadnler on DELETE request +void onDelete(const HeaderOptions &headerOption , const int eCode) +{ + try + { + if (eCode == OC_STACK_RESOURCE_DELETED) { - attributeMap = oit->getAttributeMap(); - - for (auto it = attributeMap.begin() ; it != attributeMap.end() ; ++it) - { - std::cout << "\tAttribute name: " << it->first << " value: "; - for (auto valueItr = it->second.begin() ; valueItr != it->second.end() ; ++valueItr) - { - std::cout << "\t" << *valueItr << " "; - } - - std::cout << std::endl; - } + std::cout << "DELETE request was successful" << std::endl; + } + else + { + std::cout << "onDelete Response error: " << eCode << std::endl; + std::exit(-1); } - - if (OBSERVE_TYPE_TO_USE == ObserveType::Observe) - std::cout << std::endl << "Observe is used." << std::endl << std::endl; - else if (OBSERVE_TYPE_TO_USE == ObserveType::ObserveAll) - std::cout << std::endl << "ObserveAll is used." << std::endl << std::endl; - - QueryParamsMap test; - - g_curResource->observe(ObserveType::Observe , test , &onObserve); - } - else + catch (std::exception &e) { - std::cout << "onPut Response error: " << eCode << std::endl; - std::exit(-1); + std::cout << "Exception: " << e.what() << " in onDelete" << std::endl; } } // callback handler on GET request void onGet(const HeaderOptions &headerOption , const OCRepresentation &rep , const int eCode) { + std::cout << "GET request was successful1" << std::endl; if (eCode == SUCCESS_RESPONSE) { std::cout << "GET request was successful" << std::endl; - - AttributeMap attributeMap = rep.getAttributeMap(); - - std::cout << "Resource URI: " << rep.getUri() << std::endl; - - for (auto it = attributeMap.begin() ; it != attributeMap.end() ; ++it) - { - std::cout << "\tAttribute name: " << it->first << " value: "; - for (auto valueItr = it->second.begin() ; valueItr != it->second.end() ; ++valueItr) - { - std::cout << "\t" << *valueItr << " "; - } - - std::cout << std::endl; - } - - std::vector< OCRepresentation > children = rep.getChildren(); - - for (auto oit = children.begin() ; oit != children.end() ; ++oit) - { - std::cout << "Child Resource URI: " << oit->getUri() << std::endl; - - attributeMap = oit->getAttributeMap(); - - for (auto it = attributeMap.begin() ; it != attributeMap.end() ; ++it) - { - std::cout << "\tAttribute name: " << it->first << " value: "; - for (auto valueItr = it->second.begin() ; valueItr != it->second.end() ; ++valueItr) - { - std::cout << "\t" << *valueItr << " "; - } - - std::cout << std::endl; - } - } + std::cout << "Resource URI: " << rep.getUri().c_str() << std::endl; + std::cout << "\tTemperature : " << rep.getValue("temperature") << std::endl; + std::cout << "\tHumidity : " << rep.getValue("humidity") << std::endl; } else { @@ -306,29 +296,22 @@ void PrintUsage() std::cout << " ObserveType : 2 - ObserveAll" << std::endl; } -int main(int argc , char *argv[]) +void PRINT() { + std::cout << std::endl; + std::cout << "********************************************" << std::endl; + std::cout << "* method Type : 1 - Observe *" << std::endl; + std::cout << "* method Type : 2 - Get *" << std::endl; + std::cout << "* method Type : 3 - Put *" << std::endl; + std::cout << "* method Type : 4 - Delete *" << std::endl; + std::cout << "********************************************" << std::endl; + std::cout << std::endl; +} - if (argc == 1) - { - OBSERVE_TYPE_TO_USE = ObserveType::Observe; - } - else if (argc == 2) - { - int value = atoi(argv[1]); - if (value == 1) - OBSERVE_TYPE_TO_USE = ObserveType::Observe; - else if (value == 2) - OBSERVE_TYPE_TO_USE = ObserveType::ObserveAll; - else - OBSERVE_TYPE_TO_USE = ObserveType::Observe; - } - else - { - PrintUsage(); - return -1; - } +int main(int argc , char *argv[]) +{ + int in; PlatformConfig cfg; OCPlatform::Configure(cfg); @@ -336,6 +319,30 @@ int main(int argc , char *argv[]) std::cout << "Created Platform..." << std::endl; findResourceCandidate(); + while (1) + { + PRINT(); + + std::cin >> in; + switch (in) + { + case OBSERVE: + startObserve(g_curResource); + break; + case GET: + startGet(g_curResource); + break; + case PUT: + startPut(g_curResource); + break; + case DELETE: + startDelete(g_curResource); + break; + default: + std::cout << "Invalid input, please try again" << std::endl; + break; + } + } + return 0; } - diff --git a/service/notification-manager/SampleApp/linux/sampleProvider/SampleProvider.cpp b/service/notification-manager/SampleApp/linux/sampleProvider/SampleProvider.cpp index a943b2f..2e9a23f 100755 --- a/service/notification-manager/SampleApp/linux/sampleProvider/SampleProvider.cpp +++ b/service/notification-manager/SampleApp/linux/sampleProvider/SampleProvider.cpp @@ -1,6 +1,6 @@ //****************************************************************** // -// Copyright 2014 Samsung Electronics All Rights Reserved. +// Copyright 2015 Samsung Electronics All Rights Reserved. // //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // @@ -21,6 +21,7 @@ #include #include +#include #include "OCPlatform.h" #include "OCApi.h" @@ -30,14 +31,17 @@ using namespace OC; using namespace std; +using namespace OC::OCPlatform; int g_Observation = 0; +int gQuitFlag = 0; pthread_cond_t m_cond = PTHREAD_COND_INITIALIZER; pthread_mutex_t m_mutex = PTHREAD_MUTEX_INITIALIZER; -OCEntityHandlerResult entityHandler(std::shared_ptr< OCResourceRequest > request , - std::shared_ptr< OCResourceResponse > response); + + +OCEntityHandlerResult entityHandler(std::shared_ptr< OCResourceRequest > request); class TempHumidResource { @@ -45,10 +49,9 @@ class TempHumidResource int m_temp; int m_humid; - std::string m_uri; OCResourceHandle m_resourceHandle; - + ObservationIds m_interestedObservers; OCRepresentation m_Rep; public: @@ -59,8 +62,8 @@ class TempHumidResource void createResource() { - std::string resourceURI = "/a/NM/TempHumSensor"; - std::string resourceTypeName = "NotificationManager.Hosting"; + std::string resourceURI = "/a/TempHumSensor/hosting"; + std::string resourceTypeName = "Resource.Hosting"; std::string resourceInterface = DEFAULT_INTERFACE; m_uri = resourceURI; @@ -109,7 +112,6 @@ class TempHumidResource OCRepresentation post(OCRepresentation &rep) { static int first = 1; - // for the first time it tries to create a resource if (first) { @@ -160,15 +162,20 @@ class TempHumidResource OCRepresentation get() { - cout << "resource get\n"; m_Rep.setValue("temperature", m_temp); m_Rep.setValue("humidity", m_humid); - - cout << "resource get : done\n"; - return m_Rep; } - + OCStackResult deleteDeviceResource() + { + OCStackResult result = OCPlatform::unregisterResource(m_resourceHandle); + if (OC_STACK_OK != result) + { + throw std::runtime_error( + std::string("Device Resource failed to unregister/delete") + std::to_string(result)); + } + return result; + } }; TempHumidResource myResource; @@ -210,10 +217,11 @@ void *ChangeLightRepresentation(void *param) return NULL; } -OCEntityHandlerResult entityHandler(std::shared_ptr< OCResourceRequest > request , - std::shared_ptr< OCResourceResponse > response) +OCEntityHandlerResult entityHandler(std::shared_ptr< OCResourceRequest > request) { cout << "Sample Provider entityHandler\n"; + + OCEntityHandlerResult ehResult = OC_EH_ERROR; if (request) { cout << "flag : request\n"; @@ -228,28 +236,23 @@ OCEntityHandlerResult entityHandler(std::shared_ptr< OCResourceRequest > request if (requestFlag == RequestHandlerFlag::RequestFlag) { cout << "\t\trequestFlag : Request\n"; + auto pResponse = std::make_shared(); + pResponse->setRequestHandle(request->getRequestHandle()); + pResponse->setResourceHandle(request->getResourceHandle()); + if (requestType == "GET") { cout << "\t\trequestType : GET\n"; - try - { - if (response) - { - OCRepresentation rep = myResource.get(); - cout << rep.getJSONRepresentation() << endl; - response->setErrorCode(200); - response->setResourceRepresentation(rep, DEFAULT_INTERFACE); - } - else - { - cout << "response is null\n"; - } - } - catch (exception &e) + + pResponse->setErrorCode(200); + pResponse->setResponseResult(OC_EH_OK); + pResponse->setResourceRepresentation(myResource.get()); + if (OC_STACK_OK == OCPlatform::sendResponse(pResponse)) { - cout << e.what() << endl; + ehResult = OC_EH_OK; } } + else if (requestType == "PUT") { cout << "\t\t\trequestType : PUT\n"; @@ -257,23 +260,65 @@ OCEntityHandlerResult entityHandler(std::shared_ptr< OCResourceRequest > request OCRepresentation rep = request->getResourceRepresentation(); myResource.put(rep); - if (response) + if (pResponse) { - response->setErrorCode(200); - response->setResourceRepresentation(myResource.get()); + pResponse->setErrorCode(200); + pResponse->setResourceRepresentation(myResource.get()); + } + if (OC_STACK_OK == OCPlatform::sendResponse(pResponse)) + { + ehResult = OC_EH_OK; + } + else + { + cout << "put request Error\n"; } } + else if (requestType == "POST") { + cout << "\t\t\trequestType : POST\n"; } + else if (requestType == "DELETE") { + cout << "\t\trequestType : DELETE\n"; + cout << "DeviceResource Delete Request" << std::endl; + + if (myResource.deleteDeviceResource() == OC_STACK_OK) + { + cout << "\tSuccess DELETE\n"; + pResponse->setErrorCode(200); + pResponse->setResponseResult(OC_EH_RESOURCE_DELETED); + ehResult = OC_EH_OK; + } + else + { + pResponse->setResponseResult(OC_EH_ERROR); + ehResult = OC_EH_ERROR; + } + + OCPlatform::sendResponse(pResponse); } } - else if (requestFlag & RequestHandlerFlag::ObserverFlag) + if (requestFlag & RequestHandlerFlag::ObserverFlag) { pthread_t threadId; + ObservationInfo observationInfo = request->getObservationInfo(); + if (ObserveAction::ObserveRegister == observationInfo.action) + { + myResource.m_interestedObservers.push_back(observationInfo.obsId); + } + else if (ObserveAction::ObserveUnregister == observationInfo.action) + { + myResource.m_interestedObservers.erase(std::remove( + myResource.m_interestedObservers.begin(), + myResource.m_interestedObservers.end(), + observationInfo.obsId), + myResource.m_interestedObservers.end()); + } + cout << request->getResourceUri() << endl; cout << request->getResourceRepresentation().getUri() << endl; @@ -290,6 +335,7 @@ OCEntityHandlerResult entityHandler(std::shared_ptr< OCResourceRequest > request pthread_create(&threadId , NULL , ChangeLightRepresentation , (void *) NULL); startedThread = 1; } + ehResult = OC_EH_OK; } } else @@ -297,12 +343,27 @@ OCEntityHandlerResult entityHandler(std::shared_ptr< OCResourceRequest > request std::cout << "Request invalid" << std::endl; } - return OC_EH_OK; + return ehResult; } -int main() +void quitProcess() { + unregisterResource(myResource.m_resourceHandle); + stopPresence(); + exit(0); +} +void handleSigInt(int signum) +{ + if (signum == SIGINT) + { + std::cout << " handleSigInt in" << std::endl; + quitProcess(); + } +} + +int main() +{ PlatformConfig cfg { OC::ServiceType::InProc, @@ -318,9 +379,11 @@ int main() try { + startPresence(30); myResource.createResource(); + signal(SIGINT, handleSigInt); while (true) { bool end = false; @@ -330,6 +393,7 @@ int main() cout << "2. Temp is down" << endl; cout << "3. This Program will be ended." << endl; cout << "========================================================" << endl; + cin >> number; switch (number) @@ -353,12 +417,14 @@ int main() case 3: { cout << "Bye!" << endl; + stopPresence(); end = true; + quitProcess(); break; } default: { - cout << "You type wrong number. Try again!" << endl; + cout << "Invalid input. Please try again." << endl; break; } } @@ -372,4 +438,6 @@ int main() { cout << "main exception : " << e.what() << endl; } + + } -- 2.7.4