1) changed Subscribe Accepted CB to Provider Changed CB.
2) Provider Changed CB is invoked when Provider status is changed.
3) enabled c++ wrapper
Change-Id: If07c8c71d764bd87d57f2aa519a09525bd5ef286
Signed-off-by: abitha.s <abitha.s@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/10233
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Chihyun Cho <ch79.cho@samsung.com>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
SConscript('android/SConscript')
# Go to build c++ wrapper
-#SConscript('cpp-wrapper/SConscript')
+SConscript('cpp-wrapper/SConscript')
return ;\r
}\r
\r
-void onSubscriptionAccepted(OIC::Service::NSProvider *provider)\r
+void onProviderChanged(OIC::Service::NSProvider *provider,OIC::Service::NSResponse response)\r
{\r
LOGD ("ConsumerService_onSubscriptionAccepted");\r
\r
if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();\r
return ;\r
}\r
+ //TODO: Modify to call ProviderChanged Cb adding topic in Java\r
jmethodID mid = env->GetMethodID(\r
cls,\r
"onSubscriptionAccepted",\r
\r
OIC::Service::NSConsumerService::ConsumerConfig cfg;\r
cfg.m_discoverCb = onDiscoverProvider;\r
- cfg.m_acceptedCb = onSubscriptionAccepted;\r
+ cfg.m_changedCb = onProviderChanged;\r
\r
OIC::Service::NSConsumerService::getInstance()->Start(cfg);\r
\r
if (!jServerAddress)\r
{\r
ThrowNSException(NS_ERROR, "EnableRemoteService server address NULL");\r
- return (jint) OIC::Service::Result::ERROR;\r
+ return (jint) OIC::Service::NSResult::ERROR;\r
}\r
const char *serverAddress = env->GetStringUTFChars(jServerAddress, 0);\r
- OIC::Service::Result res =\r
+ OIC::Service::NSResult res =\r
OIC::Service::NSConsumerService::getInstance()->EnableRemoteService(std::string(serverAddress));\r
env->ReleaseStringUTFChars(jServerAddress, serverAddress);\r
return (jint) res;\r
{
LOGE("Fail to set listeners");
ThrowNSException(NS_ERROR, "Listener cannot be null");
- return (jint) OIC::Service::Result::ERROR;
+ return (jint) OIC::Service::NSResult::ERROR;
}
if (g_obj_subscriptionListener != NULL)
cfg.m_syncInfoCb = onSyncInfoListenerCb;
cfg.policy = (bool) jPolicy;
- OIC::Service::Result result = OIC::Service::NSProviderService::getInstance()->Start(cfg);
- if (result != OIC::Service::Result::OK)
+ OIC::Service::NSResult result = OIC::Service::NSProviderService::getInstance()->Start(cfg);
+ if (result != OIC::Service::NSResult::OK)
{
LOGE("Fail to start NSProviderService");
{
LOGI("JNIProviderService: nativeStop - IN");
- OIC::Service::Result result = OIC::Service::NSProviderService::getInstance()->Stop();
- if (result != OIC::Service::Result::OK)
+ OIC::Service::NSResult result = OIC::Service::NSProviderService::getInstance()->Stop();
+ if (result != OIC::Service::NSResult::OK)
{
LOGI("Fail to stop NSProvider service");
return (jint) result;
{
LOGI("Fail to send notification - Message is null");
ThrowNSException(NS_ERROR, "Message cannot be null");
- return (jint) OIC::Service::Result::ERROR;
+ return (jint) OIC::Service::NSResult::ERROR;
}
OIC::Service::NSMessage *nsMsg = getMessage(env, jMsg);
if (nsMsg == nullptr)
{
ThrowNSException(NS_ERROR, "Message didn't have a field ID ");
- return (jint) OIC::Service::Result::ERROR;
+ return (jint) OIC::Service::NSResult::ERROR;
}
- OIC::Service::Result result = OIC::Service::NSProviderService::getInstance()->SendMessage(nsMsg);
- if (result != OIC::Service::Result::OK)
+ OIC::Service::NSResult result = OIC::Service::NSProviderService::getInstance()->SendMessage(nsMsg);
+ if (result != OIC::Service::NSResult::OK)
{
LOGI("Fail to send NSProvider Message");
}
if (!jstr)
{
ThrowNSException(NS_ERROR, "Server Address Can't be NULL");
- return (jint) OIC::Service::Result::ERROR;
+ return (jint) OIC::Service::NSResult::ERROR;
}
const char *address = env->GetStringUTFChars( jstr, NULL);
std::string servAddress(address);
- OIC::Service::Result result = OIC::Service::NSProviderService::getInstance()->EnableRemoteService(
+ OIC::Service::NSResult result = OIC::Service::NSProviderService::getInstance()->EnableRemoteService(
servAddress);
- if (result != OIC::Service::Result::OK)
+ if (result != OIC::Service::NSResult::OK)
{
LOGE("Fail to Enable Remote Service");
}
if (!jstr)
{
ThrowNSException(NS_ERROR, "Server Address Can't be NULL");
- return (jint) OIC::Service::Result::ERROR;
+ return (jint) OIC::Service::NSResult::ERROR;
}
const char *address = env->GetStringUTFChars( jstr, NULL);
std::string servAddress(address);
- OIC::Service::Result result = OIC::Service::NSProviderService::getInstance()->DisableRemoteService(
+ OIC::Service::NSResult result = OIC::Service::NSProviderService::getInstance()->DisableRemoteService(
servAddress);
- if (result != OIC::Service::Result::OK)
+ if (result != OIC::Service::NSResult::OK)
{
LOGE("Fail to Disable Remote Service");
}
if (!consumerClass)
{
ThrowNSException(NS_ERROR, "Failed to Get ObjectClass for Consumer");
- return (jint) OIC::Service::Result::ERROR;
+ return (jint) OIC::Service::NSResult::ERROR;
}
// Consumer ID
{
LOGE("Error: jfieldID for mConsumerId is null");
ThrowNSException(NS_ERROR, "ConsumerId not found");
- return (jint) OIC::Service::Result::ERROR;
+ return (jint) OIC::Service::NSResult::ERROR;
}
jstring jconId = (jstring)env->GetObjectField( jConsumer, fid_id);
-//******************************************************************\r
-//\r
-// Copyright 2016 Samsung Electronics All Rights Reserved.\r
-//\r
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
-//\r
-// Licensed under the Apache License, Version 2.0 (the "License");\r
-// you may not use this file except in compliance with the License.\r
-// You may obtain a copy of the License at\r
-//\r
-// http://www.apache.org/licenses/LICENSE-2.0\r
-//\r
-// Unless required by applicable law or agreed to in writing, software\r
-// distributed under the License is distributed on an "AS IS" BASIS,\r
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-// See the License for the specific language governing permissions and\r
-// limitations under the License.\r
-//\r
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
-\r
-/**\r
- * @file\r
- *\r
- * This file contains Notification service Error Codes.\r
- */\r
-\r
-#ifndef _NS_ERROR_CODE_H_\r
-#define _NS_ERROR_CODE_H_\r
-\r
-\r
-namespace OIC\r
-{\r
- namespace Service\r
- {\r
- /** Result - enumeration for NS service Result*/\r
- enum class Result\r
- {\r
- OK = 100,\r
- ERROR = 200,\r
- SUCCESS = 300,\r
- FAIL = 400,\r
- ALLOW = 500,\r
- DENY = 600,\r
- };\r
- }\r
-}\r
-#endif /* _NS_ERROR_CODE_H_ */\r
+//******************************************************************
+//
+// Copyright 2016 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+/**
+ * @file
+ *
+ * This file contains Notification service Utils.
+ */
+
+#ifndef _NS_UTILS_H_
+#define _NS_UTILS_H_
+
+
+namespace OIC
+{
+ namespace Service
+ {
+ /** NSResult - enumeration for NS service Result*/
+ enum class NSResult
+ {
+ OK = 100,
+ ERROR = 200,
+ SUCCESS = 300,
+ FAIL = 400,
+ };
+
+ /**
+ * NSResponse code of notification service
+ */
+ enum class NSResponse
+ {
+ ALLOW = 1,
+ DENY = 2,
+ TOPIC = 3,
+ };
+ }
+}
+#endif /* _NS_UTILS_H_ */
#include <list>\r
#include <algorithm>\r
#include "NSProvider.h"\r
-#include "NSErrorCode.h"\r
+#include "NSUtils.h"\r
\r
\r
namespace OIC\r
typedef void (*ProviderDiscoveredCallback)(NSProvider *);\r
\r
/**\r
- * Consumer uses this callback function on subscription accepted by provider\r
- * @param[in] provider Provider who has the notification resource\r
+ * Invoked when the provider state is changed\r
+ * @param[in] provider Provider which has the notification resource\r
+ * @param[in] response Response which has the provider state\r
*/\r
- typedef void (* AcceptedCallback)(NSProvider *);\r
+ typedef void (* ProviderChangedCallback)(NSProvider *, NSResponse);\r
\r
/**\r
* @struct ConsumerConfig\r
{\r
/** m_discoverCb - ProviderDiscoveredCallback callback listener.*/\r
ProviderDiscoveredCallback m_discoverCb;\r
- /** m_acceptedCb - AcceptedCallback callback listener.*/\r
- AcceptedCallback m_acceptedCb;\r
+ /** m_changedCb - ProviderChangedCallback callback listener.*/\r
+ ProviderChangedCallback m_changedCb;\r
} ConsumerConfig;\r
\r
/**\r
/**\r
* Request to discover to remote address as parameter.\r
* @param[in] server address combined with IP address and port number using delimiter :\r
- * @return result code of Consumer Service\r
+ * @return NSResult code of Consumer Service\r
*/\r
- Result EnableRemoteService(const std::string &serverAddress);\r
+ NSResult EnableRemoteService(const std::string &serverAddress);\r
\r
/**\r
* Request discovery manually\r
NS_LOG(DEBUG, "onNSProviderDiscovered - OUT");\r
}\r
\r
- void onNSAccepted(::NSProvider *provider)\r
+ void onNSProviderChanged(::NSProvider *provider, ::NSResponse response)\r
{\r
- NS_LOG(DEBUG, "onNSAccepted - IN");\r
+ NS_LOG(DEBUG, "onNSProviderChanged - IN");\r
+ NS_LOG_V(DEBUG, "provider Id : %s",provider->providerId);\r
+ NS_LOG_V(DEBUG, "response : %d",(int)response);\r
+ \r
NSProvider *nsProvider = new NSProvider(provider);\r
- NSConsumerService::getInstance()->getAcceptedProviders().push_back(nsProvider);\r
-\r
- if (NSConsumerService::getInstance()->getConsumerConfig().m_acceptedCb != NULL)\r
- NSConsumerService::getInstance()->getConsumerConfig().m_acceptedCb(nsProvider);\r
- NS_LOG(DEBUG, "onNSAccepted - OUT");\r
+ if(response == NS_ALLOW)\r
+ {\r
+ NSConsumerService::getInstance()->getAcceptedProviders().push_back(nsProvider);\r
+ }\r
+ else if(response == NS_DENY)\r
+ {\r
+ NSConsumerService::getInstance()->getAcceptedProviders().remove(nsProvider);\r
+ }\r
+ if (NSConsumerService::getInstance()->getConsumerConfig().m_changedCb != NULL)\r
+ NSConsumerService::getInstance()->getConsumerConfig().m_changedCb(\r
+ nsProvider, (NSResponse) response);\r
+ NS_LOG(DEBUG, "onNSProviderChanged - OUT");\r
}\r
\r
void onNSMessageReceived(::NSMessage *message)\r
NSConsumerService::NSConsumerService()\r
{\r
m_config.m_discoverCb = NULL;\r
- m_config.m_acceptedCb = NULL;\r
+ m_config.m_changedCb = NULL;\r
}\r
\r
NSConsumerService::~NSConsumerService()\r
m_config = config;\r
NSConsumerConfig nsConfig;\r
nsConfig.discoverCb = onNSProviderDiscovered;\r
- nsConfig.acceptedCb = onNSAccepted;\r
+ nsConfig.changedCb= onNSProviderChanged;\r
nsConfig.messageCb = onNSMessageReceived;\r
nsConfig.syncInfoCb = onNSSyncInfoReceived;\r
\r
return;\r
}\r
\r
- Result NSConsumerService::EnableRemoteService(const std::string &serverAddress)\r
+ NSResult NSConsumerService::EnableRemoteService(const std::string &serverAddress)\r
{\r
NS_LOG(DEBUG, "EnableRemoteService - IN");\r
- Result result = Result::ERROR;\r
+ NSResult result = NSResult::ERROR;\r
#ifdef WITH_CLOUD\r
- result = (Result) NSConsumerEnableRemoteService(OICStrdup(serverAddress.c_str()));\r
+ result = (NSResult) NSConsumerEnableRemoteService(OICStrdup(serverAddress.c_str()));\r
#else\r
NS_LOG(ERROR, "Remote Services feature is not enabled in the Build");\r
#endif\r
std::cout << "startSubscribing" << std::endl;\r
}\r
\r
-void onSubscriptionAcceptedCb(OIC::Service::NSProvider *provider)\r
+void onProviderChangedCb(OIC::Service::NSProvider *provider,OIC::Service::NSResponse response)\r
{\r
std::cout << "Subscription accepted" << std::endl;\r
std::cout << "subscribed provider Id : " << provider->getProviderId() << std::endl;\r
- provider->setListener(onNotificationPostedCb, onNotificationSyncCb);\r
+ if(response == OIC::Service::NSResponse::ALLOW)\r
+ provider->setListener(onNotificationPostedCb, onNotificationSyncCb);\r
}\r
\r
void *OCProcessThread(void *ptr)\r
\r
NSConsumerService::ConsumerConfig cfg;\r
cfg.m_discoverCb = onDiscoverNotificationCb;\r
- cfg.m_acceptedCb = onSubscriptionAcceptedCb;\r
+ cfg.m_changedCb = onProviderChangedCb;\r
\r
pthread_create(&OCThread, NULL, OCProcessThread, NULL);\r
\r
#include "NSConsumer.h"\r
#include "NSSyncInfo.h"\r
#include "NSMessage.h"\r
-#include "NSErrorCode.h"\r
+#include "NSUtils.h"\r
\r
namespace OIC\r
{\r
* and onMessageSynchronized function listeners\r
* @return :: result code of Provider Service\r
*/\r
- Result Start(ProviderConfig config);\r
+ NSResult Start(ProviderConfig config);\r
\r
/**\r
* Terminate notification service for provider\r
* @return :: result code of Provider Service\r
*/\r
- Result Stop();\r
+ NSResult Stop();\r
\r
/**\r
* Request to publish resource to cloud server\r
* @param[in] server address combined with IP address and port number using delimiter :\r
* @return result code of Provider Service\r
*/\r
- Result EnableRemoteService(const std::string &serverAddress);\r
+ NSResult EnableRemoteService(const std::string &serverAddress);\r
\r
/**\r
* Request to cancel remote service using cloud server\r
* @param[in] server address combined with IP address and port number using delimiter :\r
* @return result code of Provider Service\r
*/\r
- Result DisableRemoteService(const std::string &serverAddress);\r
+ NSResult DisableRemoteService(const std::string &serverAddress);\r
\r
/**\r
* Send notification message to all subscribers\r
* @param[in] msg Notification message including id, title, contentText\r
* @return :: result code of Provider Service\r
*/\r
- Result SendMessage(NSMessage *msg);\r
+ NSResult SendMessage(NSMessage *msg);\r
\r
\r
/**\r
return &s_instance;\r
}\r
\r
- Result NSProviderService::Start(NSProviderService::ProviderConfig config)\r
+ NSResult NSProviderService::Start(NSProviderService::ProviderConfig config)\r
{\r
NS_LOG(DEBUG, "Start - IN");\r
\r
nsConfig.policy = config.policy;\r
nsConfig.userInfo = OICStrdup(config.userInfo.c_str());\r
\r
- Result result = (Result) NSStartProvider(nsConfig);\r
+ NSResult result = (NSResult) NSStartProvider(nsConfig);\r
NS_LOG(DEBUG, "Start - OUT");\r
return result;\r
}\r
\r
- Result NSProviderService::Stop()\r
+ NSResult NSProviderService::Stop()\r
{\r
NS_LOG(DEBUG, "Stop - IN");\r
- Result result = (Result) NSStopProvider();\r
+ NSResult result = (NSResult) NSStopProvider();\r
NS_LOG(DEBUG, "Stop - OUT");\r
return result;\r
}\r
\r
- Result NSProviderService::EnableRemoteService(const std::string &serverAddress)\r
+ NSResult NSProviderService::EnableRemoteService(const std::string &serverAddress)\r
{\r
NS_LOG(DEBUG, "EnableRemoteService - IN");\r
- Result result = Result::ERROR;\r
+ NSResult result = NSResult::ERROR;\r
#ifdef WITH_CLOUD\r
- result = (Result) NSProviderEnableRemoteService(OICStrdup(serverAddress.c_str()));\r
+ result = (NSResult) NSProviderEnableRemoteService(OICStrdup(serverAddress.c_str()));\r
#else\r
NS_LOG(ERROR, "Remote Services feature is not enabled in the Build");\r
#endif\r
return result;\r
}\r
\r
- Result NSProviderService::DisableRemoteService(const std::string &serverAddress)\r
+ NSResult NSProviderService::DisableRemoteService(const std::string &serverAddress)\r
{\r
NS_LOG(DEBUG, "DisableRemoteService - IN");\r
- Result result = Result::ERROR;\r
+ NSResult result = NSResult::ERROR;\r
#ifdef WITH_CLOUD\r
- result = (Result) NSProviderDisableRemoteService(OICStrdup(serverAddress.c_str()));\r
+ result = (NSResult) NSProviderDisableRemoteService(OICStrdup(serverAddress.c_str()));\r
#else\r
NS_LOG(ERROR, "Remote Services feature is not enabled in the Build");\r
#endif\r
return result;\r
}\r
\r
- Result NSProviderService::SendMessage(NSMessage *msg)\r
+ NSResult NSProviderService::SendMessage(NSMessage *msg)\r
{\r
NS_LOG(DEBUG, "SendMessage - IN");\r
- Result result = Result::ERROR;\r
+ NSResult result = NSResult::ERROR;\r
if (msg != nullptr)\r
- result = (Result) NSSendMessage(getNSMessage(msg));\r
+ result = (NSResult) NSSendMessage(getNSMessage(msg));\r
else\r
NS_LOG(DEBUG, "Empty Message");\r
NS_LOG(DEBUG, "SendMessage - OUT");\r