Added C++ wrapper for the Notification Service Provider and Consumer.
authorAbitha Shankar <abitha.s@samsung.com>
Fri, 22 Jul 2016 09:57:46 +0000 (15:27 +0530)
committerUze Choi <uzchoi@samsung.com>
Tue, 26 Jul 2016 00:38:30 +0000 (00:38 +0000)
1) added wrapper C++ Api's class for NS Provider and NS Resources
2) added wrapper C++ Api's class for NS Consumer
3) added sample applications to test the equivalent functionality from wrapper api's

patch 1 : initial commit for Provider code with Basic API implementation
patch 2 : Updated the code with new design of classes to be in line with API's in android.
patch 3 : Review comments addressed and updated the code.
patch 4 : added appropriate flags for build failure in android
patch 5 : Removed redundant NS prefix and added changes to reduce coupling between Provider classes.
  Added Notification Consumer code changes and test application for the same.
  Refractered the code with respect to folder structure
patch 6 : updated comments
patch 7 : Modified api's for changes in c api's
patch 8 : updated review comments
patch 9 : updated Doxygen comments
patch 10/11 : rebase to latest
patch 12 : review comments changes to rename files with NS* prefix and added Under OIC::Service namespace
patch 13 : added implementation for Message and SyncInfo cb to call appropriate Provider cb.
patch 14 : updated with the latest API changes with respect to refractoring listeners and added logs
patch 15 : updated with RemoteService APIs for Consumer and Provider and rebased to latest.
patch 16 : rebase to latest

Change-Id: I08c49ed2d5b1d351fc94305aa47ba9dfc18a8844
Signed-off-by: Abitha Shankar <abitha.s@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/8635
Reviewed-by: Chihyun Cho <ch79.cho@samsung.com>
Reviewed-by: Hun-je Yeon <hunje.yeon@samsung.com>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
21 files changed:
service/notification/SConscript
service/notification/cpp-wrapper/SConscript [new file with mode: 0755]
service/notification/cpp-wrapper/common/NSMediaContents.cpp [new file with mode: 0755]
service/notification/cpp-wrapper/common/NSMediaContents.h [new file with mode: 0755]
service/notification/cpp-wrapper/common/NSMessage.cpp [new file with mode: 0755]
service/notification/cpp-wrapper/common/NSMessage.h [new file with mode: 0755]
service/notification/cpp-wrapper/common/NSSyncInfo.cpp [new file with mode: 0755]
service/notification/cpp-wrapper/common/NSSyncInfo.h [new file with mode: 0755]
service/notification/cpp-wrapper/consumer/SConscript [new file with mode: 0755]
service/notification/cpp-wrapper/consumer/inc/NSConsumerService.h [new file with mode: 0755]
service/notification/cpp-wrapper/consumer/inc/NSProvider.h [new file with mode: 0755]
service/notification/cpp-wrapper/consumer/src/NSConsumerService.cpp [new file with mode: 0755]
service/notification/cpp-wrapper/consumer/src/NSProvider.cpp [new file with mode: 0755]
service/notification/cpp-wrapper/examples/linux/SConscript [new file with mode: 0755]
service/notification/cpp-wrapper/examples/linux/notificationserviceconsumer.cpp [new file with mode: 0755]
service/notification/cpp-wrapper/examples/linux/notificationserviceprovider.cpp [new file with mode: 0755]
service/notification/cpp-wrapper/provider/SConscript [new file with mode: 0755]
service/notification/cpp-wrapper/provider/inc/NSConsumer.h [new file with mode: 0755]
service/notification/cpp-wrapper/provider/inc/NSProviderService.h [new file with mode: 0755]
service/notification/cpp-wrapper/provider/src/NSConsumer.cpp [new file with mode: 0755]
service/notification/cpp-wrapper/provider/src/NSProviderService.cpp [new file with mode: 0755]

index 1378cf1..e9aa079 100644 (file)
@@ -136,3 +136,6 @@ SConscript('examples/SConscript')
 # Go to build jni
 if target_os == 'android':
     SConscript('android/SConscript')
+
+ # Go to build c++ wrapper
+SConscript('cpp-wrapper/SConscript')
\ No newline at end of file
diff --git a/service/notification/cpp-wrapper/SConscript b/service/notification/cpp-wrapper/SConscript
new file mode 100755 (executable)
index 0000000..8178583
--- /dev/null
@@ -0,0 +1,8 @@
+# build producer notification wrapper
+SConscript('provider/SConscript')
+
+# build producer notification wrapper
+SConscript('consumer/SConscript')
+
+# Go to build sample apps using wrapper
+SConscript('examples/linux/SConscript')
diff --git a/service/notification/cpp-wrapper/common/NSMediaContents.cpp b/service/notification/cpp-wrapper/common/NSMediaContents.cpp
new file mode 100755 (executable)
index 0000000..dc8399c
--- /dev/null
@@ -0,0 +1,46 @@
+//******************************************************************\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
+#include "NSMediaContents.h"\r
+\r
+namespace OIC\r
+{\r
+    namespace Service\r
+    {\r
+        NSMediaContents::NSMediaContents(::NSMediaContents *mediacontents)\r
+        {\r
+            if (mediacontents != nullptr)\r
+            {\r
+                if ((mediacontents->iconImage != nullptr) && strlen(mediacontents->iconImage))\r
+                    m_iconImage.assign(mediacontents->iconImage, strlen(mediacontents->iconImage));\r
+            }\r
+        }\r
+\r
+        std::string NSMediaContents::getIconImage() const\r
+        {\r
+            return m_iconImage;\r
+        }\r
+\r
+        void NSMediaContents::setIconImage(const std::string &iconImage)\r
+        {\r
+            m_iconImage = iconImage;\r
+        }\r
+    }\r
+}\r
diff --git a/service/notification/cpp-wrapper/common/NSMediaContents.h b/service/notification/cpp-wrapper/common/NSMediaContents.h
new file mode 100755 (executable)
index 0000000..da06bc7
--- /dev/null
@@ -0,0 +1,93 @@
+//******************************************************************\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 media contents representation.\r
+ */\r
+\r
+#ifndef _NS_MEDIA_CONTENTS_H_\r
+#define _NS_MEDIA_CONTENTS_H_\r
+\r
+\r
+#include <string>\r
+#include "NSCommon.h"\r
+#include "oic_string.h"\r
+#include "string.h"\r
+\r
+namespace OIC\r
+{\r
+    namespace Service\r
+    {\r
+        /**\r
+         * @class   NSMediaContents\r
+         * @brief   This class provides a set of APIs for Notification service Media Contents.\r
+         */\r
+        class NSMediaContents\r
+        {\r
+            public:\r
+                /**\r
+                     * Constructor of NSMediaContents.\r
+                     */\r
+                NSMediaContents() = default;\r
+\r
+                /**\r
+                     * Constructor of NSMediaContents.\r
+                     *\r
+                     * @param mediacontents - pointer to NSMediaContents struct to initialize.\r
+                     */\r
+                NSMediaContents(::NSMediaContents *mediacontents);\r
+\r
+                /**\r
+                     * Constructor of NSMediaContents.\r
+                     *\r
+                     * @param iconImage - iconImage of the Notification service MediaContents.\r
+                     */\r
+                NSMediaContents(const std::string &iconImage)\r
+                    : m_iconImage(iconImage) {}\r
+\r
+\r
+                /**\r
+                     * Destructor of NSMediaContents.\r
+                     */\r
+                ~NSMediaContents() = default;\r
+\r
+                /**\r
+                      * This method is for getting icon image from the Notification service media contents.\r
+                      *\r
+                      * @return iconImage as string.\r
+                      */\r
+                std::string getIconImage() const;\r
+\r
+                /**\r
+                      * This method is for setting icon image for the Notification service media contents.\r
+                      *\r
+                      * @param iconImage - as string.\r
+                      */\r
+                void setIconImage(const std::string &iconImage);\r
+\r
+            private:\r
+                std::string m_iconImage;\r
+\r
+        };\r
+    }\r
+}\r
+#endif /* _NS_MEDIA_CONTENTS_H_ */\r
diff --git a/service/notification/cpp-wrapper/common/NSMessage.cpp b/service/notification/cpp-wrapper/common/NSMessage.cpp
new file mode 100755 (executable)
index 0000000..763cf80
--- /dev/null
@@ -0,0 +1,140 @@
+//******************************************************************\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
+#include "NSMessage.h"\r
+\r
+namespace OIC\r
+{\r
+    namespace Service\r
+    {\r
+        NSMessage::NSMessage(::NSMessage *msg)\r
+        {\r
+            if (msg != nullptr)\r
+            {\r
+                m_messageId = msg->messageId;\r
+\r
+                if ((msg->providerId != nullptr) && strlen(msg->providerId))\r
+                    m_providerId.assign(msg->providerId, strlen(msg->providerId));\r
+\r
+                m_type = (NSMessageType)msg->type;\r
+\r
+                if ((msg->dateTime != nullptr) && strlen(msg->dateTime))\r
+                    m_time.assign(msg->dateTime, strlen(msg->dateTime));\r
+\r
+                m_ttl =  msg->ttl;\r
+\r
+                if ((msg->title != nullptr) && strlen(msg->title))\r
+                    m_title.assign(msg->title, strlen(msg->title));\r
+\r
+                if ((msg->contentText != nullptr) && strlen(msg->contentText))\r
+                    m_contentText.assign(msg->contentText, strlen(msg->contentText));\r
+\r
+                if ((msg->sourceName != nullptr) && strlen(msg->sourceName))\r
+                    m_sourceName.assign(msg->sourceName, strlen(msg->sourceName));\r
+\r
+                m_mediaContents = new NSMediaContents();\r
+                if (msg->mediaContents != nullptr)\r
+                    if ((msg->mediaContents->iconImage != nullptr) && strlen(msg->mediaContents->iconImage))\r
+                        m_mediaContents->setIconImage(msg->mediaContents->iconImage);\r
+\r
+            }\r
+        }\r
+\r
+        uint64_t NSMessage::getMessageId() const\r
+        {\r
+            return m_messageId;\r
+        }\r
+\r
+        std::string NSMessage::getProviderId() const\r
+        {\r
+            return m_providerId;\r
+        }\r
+\r
+        NSMessage::NSMessageType NSMessage::getType() const\r
+        {\r
+            return m_type;\r
+        }\r
+\r
+        std::string NSMessage::getTime() const\r
+        {\r
+            return m_time;\r
+        }\r
+\r
+        uint64_t NSMessage::getTTL() const\r
+        {\r
+            return m_ttl;\r
+        }\r
+\r
+        std::string NSMessage::getTitle() const\r
+        {\r
+            return m_title;\r
+        }\r
+\r
+        std::string NSMessage::getContentText() const\r
+        {\r
+            return m_contentText;\r
+        }\r
+\r
+        std::string NSMessage::getSourceName() const\r
+        {\r
+            return m_sourceName;\r
+        }\r
+\r
+        NSMediaContents *NSMessage::getMediaContents() const\r
+        {\r
+            return m_mediaContents;\r
+        }\r
+\r
+        void NSMessage::setType(const NSMessageType &type)\r
+        {\r
+            m_type = type;\r
+        }\r
+\r
+        void NSMessage::setTime(const std::string &time)\r
+        {\r
+            m_time = time;\r
+        }\r
+\r
+        void NSMessage::setTTL(const uint64_t &ttl)\r
+        {\r
+            m_ttl = ttl;\r
+        }\r
+\r
+        void NSMessage::setTitle(const std::string &title)\r
+        {\r
+            m_title = title;\r
+        }\r
+\r
+        void NSMessage::setContentText(const std::string &contextText)\r
+        {\r
+            m_contentText = contextText;\r
+        }\r
+\r
+        void NSMessage::setSourceName(const std::string &sourceName)\r
+        {\r
+            m_sourceName = sourceName;\r
+        }\r
+\r
+        void NSMessage::setMediaContents(NSMediaContents *mediaContents)\r
+        {\r
+            m_mediaContents = mediaContents;\r
+        }\r
+    }\r
+}\r
diff --git a/service/notification/cpp-wrapper/common/NSMessage.h b/service/notification/cpp-wrapper/common/NSMessage.h
new file mode 100755 (executable)
index 0000000..f691e23
--- /dev/null
@@ -0,0 +1,200 @@
+//******************************************************************\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 Message representation.\r
+ */\r
+\r
+#ifndef _NS_MESSAGE_H_\r
+#define _NS_MESSAGE_H_\r
+\r
+#include "NSMediaContents.h"\r
+#include "oic_string.h"\r
+#include <cstdint>\r
+#include "string.h"\r
+\r
+namespace OIC\r
+{\r
+    namespace Service\r
+    {\r
+        /**\r
+         * @class   NSMessage\r
+         * @brief   This class provides a set of APIs for Notification service Message .\r
+         */\r
+        class NSMessage\r
+        {\r
+            public:\r
+                /** NSMessageType - enumeration for Notification service MessageType*/\r
+                enum class NSMessageType\r
+                {\r
+                    NS_MESSAGE_ALERT = 0,\r
+                    NS_MESSAGE_NOTICE = 1,\r
+                    NS_MESSAGE_EVENT = 2,\r
+                    NS_MESSAGE_INFO = 3,\r
+                };\r
+\r
+                /**\r
+                        * Constructor of NSMessage.\r
+                        */\r
+                NSMessage(): m_mediaContents(new NSMediaContents) { }\r
+\r
+                /**\r
+                        * Constructor of NSMessage.\r
+                        *\r
+                        * @param msg - pointer to NSMessage struct to initialize.\r
+                        */\r
+                NSMessage(::NSMessage *msg);\r
+\r
+                /**\r
+                        * Destructor of NSMessage.\r
+                        */\r
+                ~NSMessage() = default;\r
+\r
+                /**\r
+                     * This method is for getting Message Id from the Notification service Message.\r
+                     *\r
+                     * @return Id as uint64_t.\r
+                     */\r
+                uint64_t getMessageId() const;\r
+\r
+                /**\r
+                     * This method is for getting Provider Id from the Notification service Message.\r
+                     *\r
+                     * @return Id as string.\r
+                     */\r
+                std::string getProviderId() const;\r
+\r
+                /**\r
+                     * This method is for getting type from the Notification service Message.\r
+                     *\r
+                     * @return type as NSMessageType.\r
+                     */\r
+                NSMessageType getType() const;\r
+\r
+                /**\r
+                     * This method is for setting type from the Notification service Message.\r
+                     *\r
+                     * @param type as NSMessageType.\r
+                     */\r
+                void setType(const NSMessageType &type);\r
+\r
+                /**\r
+                     * This method is for getting time from the Notification service Message.\r
+                     *\r
+                     * @return time as string.\r
+                     */\r
+                std::string getTime() const;\r
+\r
+                /**\r
+                     * This method is for setting time from the Notification service Message.\r
+                     *\r
+                     * @param time as string.\r
+                     */\r
+                void setTime(const std::string &time);\r
+\r
+                /**\r
+                     * This method is for getting time to live from the Notification service Message.\r
+                     *\r
+                     * @return ttl as uint64_t.\r
+                     */\r
+                uint64_t getTTL() const;\r
+\r
+                /**\r
+                     * This method is for setting time to live from the Notification service Message.\r
+                     *\r
+                     * @param ttl as uint64_t.\r
+                     */\r
+                void setTTL(const uint64_t &ttl);\r
+\r
+                /**\r
+                     * This method is for getting Title from the Notification service Message.\r
+                     *\r
+                     * @return Title as string.\r
+                     */\r
+                std::string getTitle() const;\r
+\r
+                /**\r
+                     * This method is for setting Title from the Notification service Message.\r
+                     *\r
+                     * @param Title as string.\r
+                     */\r
+                void setTitle(const std::string &title);\r
+\r
+                /**\r
+                     * This method is for getting contentText from the Notification service Message.\r
+                     *\r
+                     * @return contentText as string.\r
+                     */\r
+                std::string getContentText() const;\r
+\r
+                /**\r
+                     * This method is for setting contentText from the Notification service Message.\r
+                     *\r
+                     * @param contentText as string.\r
+                     */\r
+                void setContentText(const std::string &contextText);\r
+\r
+                /**\r
+                     * This method is for getting sourceName from the Notification service Message.\r
+                     *\r
+                     * @return sourceName as string.\r
+                     */\r
+                std::string getSourceName() const;\r
+\r
+                /**\r
+                     * This method is for setting sourceName from the Notification service Message.\r
+                     *\r
+                     * @param sourceName as string.\r
+                     */\r
+                void setSourceName(const std::string &sourceName);\r
+\r
+                /**\r
+                     * This method is for getting mediaContents from the Notification service Message.\r
+                     *\r
+                     * @return mediaContents as NSMediaContents pointer.\r
+                     */\r
+                NSMediaContents *getMediaContents() const;\r
+\r
+                /**\r
+                     * This method is for setting mediaContents from the Notification service Message.\r
+                     *\r
+                     * @param mediaContents as NSMediaContents pointer.\r
+                     */\r
+                void setMediaContents(NSMediaContents *mediaContents);\r
+\r
+\r
+            private:\r
+                uint64_t m_messageId;\r
+                std::string m_providerId;\r
+\r
+                NSMessageType m_type;\r
+                std::string m_time;\r
+                uint64_t m_ttl;\r
+                std::string m_title;\r
+                std::string m_contentText;\r
+                std::string m_sourceName;\r
+                NSMediaContents *m_mediaContents;\r
+\r
+        };\r
+    }\r
+}\r
+#endif /* _NS_MESSAGE_H_ */\r
diff --git a/service/notification/cpp-wrapper/common/NSSyncInfo.cpp b/service/notification/cpp-wrapper/common/NSSyncInfo.cpp
new file mode 100755 (executable)
index 0000000..4f41dbf
--- /dev/null
@@ -0,0 +1,55 @@
+//******************************************************************\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
+#include "NSSyncInfo.h"\r
+\r
+namespace OIC\r
+{\r
+    namespace Service\r
+    {\r
+        NSSyncInfo::NSSyncInfo(::NSSyncInfo *syncInfo)\r
+        {\r
+            if (syncInfo != nullptr)\r
+            {\r
+                m_messageId = syncInfo->messageId;\r
+\r
+                if ((syncInfo->providerId != nullptr) && strlen(syncInfo->providerId))\r
+                    m_providerId.assign(syncInfo->providerId, strlen(syncInfo->providerId));\r
+\r
+                m_state = (NSSyncType) syncInfo->state;\r
+            }\r
+        }\r
+\r
+        uint64_t NSSyncInfo::getMessageId() const\r
+        {\r
+            return m_messageId;\r
+        }\r
+\r
+        std::string NSSyncInfo::getProviderId() const\r
+        {\r
+            return m_providerId;\r
+        }\r
+\r
+        NSSyncInfo::NSSyncType NSSyncInfo::getState() const\r
+        {\r
+            return m_state;\r
+        }\r
+    }\r
+}\r
diff --git a/service/notification/cpp-wrapper/common/NSSyncInfo.h b/service/notification/cpp-wrapper/common/NSSyncInfo.h
new file mode 100755 (executable)
index 0000000..f4b4ef5
--- /dev/null
@@ -0,0 +1,111 @@
+//******************************************************************\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 SyncInfo representation.\r
+ */\r
+\r
+#ifndef _NS_SYNC_INFO_H_\r
+#define _NS_SYNC_INFO_H_\r
+\r
+#include <string>\r
+#include "NSCommon.h"\r
+#include "oic_string.h"\r
+#include "string.h"\r
+\r
+namespace OIC\r
+{\r
+    namespace Service\r
+    {\r
+        /**\r
+         * @class   NSSyncInfo\r
+         * @brief   This class provides a set of APIs for Notification service SyncInfo .\r
+         */\r
+        class NSSyncInfo\r
+        {\r
+            public:\r
+                /** NSSyncType - enumeration for Notification service SyncType*/\r
+                enum class NSSyncType\r
+                {\r
+                    NS_SYNC_UNREAD = 0,\r
+                    NS_SYNC_READ = 1,\r
+                    NS_SYNC_DELETED = 2,\r
+                };\r
+\r
+                /**\r
+                        * Constructor of NSSyncInfo.\r
+                        */\r
+                NSSyncInfo() = default;\r
+\r
+                /**\r
+                        * Constructor of NSSyncInfo.\r
+                        *\r
+                        * @param syncInfo - pointer to NSSyncInfo struct to initialize.\r
+                        */\r
+                NSSyncInfo(::NSSyncInfo *syncInfo);\r
+\r
+\r
+                /**\r
+                        * Constructor of NSSyncInfo.\r
+                        *\r
+                        * @param messageId - messageId of the Notification SyncInfo.\r
+                        * @param providerId - providerId of the Notification SyncInfo.\r
+                        * @param state - state of the Notification SyncInfo.\r
+                        */\r
+                NSSyncInfo(const uint64_t &messageId, const std::string &providerId,\r
+                           const NSSyncType &state)\r
+                    : m_messageId(messageId), m_providerId(providerId), m_state(state) {}\r
+\r
+                /**\r
+                        * Destructor of NSSyncInfo.\r
+                        */\r
+                ~NSSyncInfo() = default;\r
+\r
+                /**\r
+                     * This method is for getting Message Id from the Notification service sync info.\r
+                     *\r
+                     * @return Id as uint64_t.\r
+                     */\r
+                uint64_t getMessageId() const;\r
+\r
+                /**\r
+                     * This method is for getting Provider Id from the Notification service sync info.\r
+                     *\r
+                     * @return Id as string.\r
+                     */\r
+                std::string getProviderId() const;\r
+\r
+                /**\r
+                     * This method is for getting state from the Notification service sync info.\r
+                     *\r
+                     * @return state as NSSyncType.\r
+                     */\r
+                NSSyncType getState() const;\r
+\r
+            private:\r
+                uint64_t m_messageId;\r
+                std::string m_providerId;\r
+                NSSyncType m_state;\r
+        };\r
+    }\r
+}\r
+#endif /* _NS_SYNC_INFO_H_ */\r
diff --git a/service/notification/cpp-wrapper/consumer/SConscript b/service/notification/cpp-wrapper/consumer/SConscript
new file mode 100755 (executable)
index 0000000..beef822
--- /dev/null
@@ -0,0 +1,70 @@
+#******************************************************************
+#
+# 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.
+#
+#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+##
+# Notification Service c++ wrapper build script
+##
+
+import platform
+Import('env')
+
+if env.get('RELEASE'):
+       env.AppendUnique(CCFLAGS = ['-Os'])
+       env.AppendUnique(CPPDEFINES = ['NDEBUG'])
+else:
+       env.AppendUnique(CCFLAGS = ['-g'])
+
+if env.get('LOGGING'):
+       env.AppendUnique(CPPDEFINES = ['TB_LOG'])
+
+lib_env = env.Clone()
+SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env')
+notification_env = lib_env.Clone()
+
+target_os = env.get('TARGET_OS')
+
+######################################################################
+# Build flags
+######################################################################
+notification_env.AppendUnique(CPPPATH = ['../../include'])
+notification_env.AppendUnique(CPPPATH = ['inc'])
+notification_env.AppendUnique(CPPPATH = ['../common'])
+notification_env.AppendUnique(CPPPATH = ['../provider/inc'])
+notification_env.AppendUnique(CPPPATH = ['../../src/common'])
+
+notification_env.PrependUnique(LIBS = [
+       'oc_logger',
+       'libnotification_consumer'
+       ])
+notification_env.AppendUnique(CXXFLAGS = ['-O2', '-Wall', '-fmessage-length=0', '-std=c++0x','-frtti'])
+if target_os == 'android':
+    notification_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
+    notification_env.PrependUnique(LIBS = ['gnustl_shared', 'log'])
+
+######################################################################
+# Source files and Targets
+######################################################################
+
+notification_consumer_src = [
+       env.Glob('src/*.cpp'),env.Glob('../common/*.cpp')]
+
+consumersdk = notification_env.SharedLibrary('notification_consumer_wrapper', notification_consumer_src)
+notification_env.InstallTarget(consumersdk, 'libnotification_consumer_wrapper')
+notification_env.UserInstallTargetLib(consumersdk, 'libnotification_consumer_wrapper')
diff --git a/service/notification/cpp-wrapper/consumer/inc/NSConsumerService.h b/service/notification/cpp-wrapper/consumer/inc/NSConsumerService.h
new file mode 100755 (executable)
index 0000000..3be2595
--- /dev/null
@@ -0,0 +1,143 @@
+//******************************************************************\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
+/**\r
+ * @file\r
+ *\r
+ * This file provides C++ Wrapper APIs of Notification Service for Consumer.\r
+ */\r
+\r
+#ifndef _NS_CONSUMER_SERVICE_H_\r
+#define _NS_CONSUMER_SERVICE_H_\r
+\r
+#include "NSCommon.h"\r
+#include "NSConsumerInterface.h"\r
+#include <list>\r
+#include <algorithm>\r
+#include "NSConstants.h"\r
+\r
+\r
+namespace OIC\r
+{\r
+    namespace Service\r
+    {\r
+        class NSProvider;\r
+        /**\r
+         * @class   NSConsumerService\r
+         * @brief   This class provides a set of C++APIs for Notification Consumer.\r
+         */\r
+        class NSConsumerService\r
+        {\r
+\r
+            public :\r
+                /**\r
+                     * Consumer uses this callback function to receive the discovered providers\r
+                     * @param[in] provider        Provider who has the notification resource\r
+                     */\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
+                     */\r
+                typedef void (* AcceptedCallback)(NSProvider *);\r
+\r
+                /**\r
+                     * @struct   ConsumerConfig\r
+                     * @brief Consumer sets this callback function configuration for registering callbacks\r
+                     *\r
+                     */\r
+                typedef struct\r
+                {\r
+                    /** m_discoverCb - ProviderDiscoveredCallback callback listener.*/\r
+                    ProviderDiscoveredCallback m_discoverCb;\r
+                    /** m_acceptedCb - AcceptedCallback callback listener.*/\r
+                    AcceptedCallback m_acceptedCb;\r
+                } ConsumerConfig;\r
+\r
+                /**\r
+                      * API for getting the Instance of NSConsumerService class\r
+                      *\r
+                      * @return Instance of the "NSConsumerService" class\r
+                      */\r
+                static NSConsumerService *getInstance();\r
+\r
+                /**\r
+                      * Initialize notification service for consumer\r
+                      * @param[in]  config   ConsumerConfig Callback function pointers to onDiscoverd,\r
+                      * OnAccepted, OnMessageReceived and OnSyncInfoReceived functions\r
+                      */\r
+                void Start(ConsumerConfig config);\r
+\r
+                /**\r
+                      * Terminate notification service for consumer\r
+                      */\r
+                void Stop();\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 NSResult\r
+                     */\r
+                NSResult EnableRemoteService(const std::string &serverAddress);\r
+\r
+                /**\r
+                      * Request discovery manually\r
+                      */\r
+                void RescanProvider();\r
+\r
+                /**\r
+                      *  request to get NSProvider pointer\r
+                      * @param id -id as string\r
+                      *\r
+                      * @return pointer to NSProvider\r
+                      */\r
+                NSProvider *getProvider(const std::string &id);\r
+\r
+                /**\r
+                      *  get consumer config values\r
+                      * @return ConsumerConfig callbaks set\r
+                      */\r
+                ConsumerConfig getConsumerConfig();\r
+\r
+                /**\r
+                      *  get list of providers acceted.\r
+                      * @return m_acceptedProviders -list of accepted providers\r
+                      */\r
+                std::list<NSProvider *> getAcceptedProviders();\r
+\r
+            private :\r
+                ConsumerConfig m_config;\r
+                std::list<NSProvider *> m_acceptedProviders;\r
+\r
+            private :\r
+                NSConsumerService();\r
+                ~NSConsumerService();\r
+                NSConsumerService(const NSConsumerService & ) = delete;\r
+                NSConsumerService &operator=(const NSConsumerService & ) = delete;\r
+                NSConsumerService(const NSConsumerService &&) = delete;\r
+                NSConsumerService &operator=(const NSConsumerService && ) = delete;\r
+\r
+        };\r
+    }\r
+}\r
+\r
+#endif //_NS_CONSUMER_SERVICE_H_\r
diff --git a/service/notification/cpp-wrapper/consumer/inc/NSProvider.h b/service/notification/cpp-wrapper/consumer/inc/NSProvider.h
new file mode 100755 (executable)
index 0000000..6f23bc4
--- /dev/null
@@ -0,0 +1,151 @@
+//******************************************************************\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 Provider representation.\r
+ */\r
+\r
+#ifndef _NS_PROVIDER_H_\r
+#define _NS_PROVIDER_H_\r
+\r
+\r
+#include <string>\r
+#include <cstring>\r
+#include "oic_string.h"\r
+#include "NSSyncInfo.h"\r
+#include "NSConstants.h"\r
+\r
+namespace OIC\r
+{\r
+    namespace Service\r
+    {\r
+        class NSMessage;\r
+        class NSSyncInfo;\r
+        /**\r
+         * @class   NSProvider\r
+         * @brief   This class provides a set of Notification service Provider representation APIs.\r
+         */\r
+        class NSProvider\r
+        {\r
+            public:\r
+                /**\r
+                     * Consumer use this callback function to receive notification message from provider\r
+                     * synchronization\r
+                     * @param[in] message     Notification message\r
+                     */\r
+                typedef void (*MessageReceivedCallback)(NSMessage *);\r
+\r
+                /**\r
+                     * Provider and consumer use this callback function to receive the status of the message\r
+                     * synchronization\r
+                     * @param[in] sync        Synchronization information of the notification message\r
+                     */\r
+                typedef void (*SyncInfoReceivedCallback)(NSSyncInfo *);\r
+\r
+                /**\r
+                      * Constructor of NSProvider.\r
+                      */\r
+                NSProvider(): m_messageCb(NULL), m_syncInfoCb(NULL) {}\r
+\r
+                /**\r
+                      * Constructor of NSProvider.\r
+                      *\r
+                      * @param providerId - providerId of the Notification.\r
+                      */\r
+                NSProvider(const std::string &providerId) : m_providerId(providerId),\r
+                    m_messageCb(NULL), m_syncInfoCb(NULL) {}\r
+\r
+                /**\r
+                      * Constructor of NSProvider.\r
+                      *\r
+                      * @param provider - of type NSProvider.\r
+                      */\r
+                NSProvider(::NSProvider *provider);\r
+\r
+\r
+                /**\r
+                      * Destructor of NSProvider.\r
+                      */\r
+                ~NSProvider() = default;\r
+\r
+                /**\r
+                      * This method is for getting ProviderId from the Notification service provider.\r
+                      *\r
+                      * @return ProviderId as string.\r
+                      */\r
+                std::string getProviderId() const;\r
+\r
+                /**\r
+                      * This method is for requesting subscription of Notification service.\r
+                      *\r
+                      */\r
+                void subscribe();\r
+\r
+                /**\r
+                      * This method is for requesting unsubscription of Notification service.\r
+                      *\r
+                      */\r
+                void unSubscribe();\r
+\r
+                /**\r
+                      * This method is for Sending SyncInfo of Notification service.\r
+                      *\r
+                      * @param messageId - id of type message.\r
+                      * @param type - NSSyncType of Notification service.\r
+                      */\r
+                void SendSyncInfo(uint64_t messageId, NSSyncInfo::NSSyncType type);\r
+\r
+                /**\r
+                      * This method is for registering for listeners of Notification .\r
+                      *\r
+                      * @param messageHandle - MessageReceivedCallback callback.\r
+                      * @param syncHandle - SyncInfoReceivedCallback callback\r
+                      */\r
+                void setListener(MessageReceivedCallback messageHandle,\r
+                                 SyncInfoReceivedCallback syncHandle);\r
+\r
+                /**\r
+                      * This method is for getting the registered cb of Notification message received.\r
+                      *\r
+                      * @return messageCb - MessageReceivedCallback .\r
+                      */\r
+                MessageReceivedCallback getMessageReceivedCb();\r
+\r
+                /**\r
+                      * This method is for getting the registered cb of Notification SyncInfo received.\r
+                      *\r
+                      * @return syncInfoCb - SyncInfoReceivedCallback .\r
+                      */\r
+                SyncInfoReceivedCallback getSyncInfoReceivedCb();\r
+\r
+            private:\r
+                ::NSProvider *getNSProvider();\r
+\r
+            private:\r
+                std::string m_providerId;\r
+                MessageReceivedCallback m_messageCb;\r
+                SyncInfoReceivedCallback m_syncInfoCb;\r
+\r
+        };\r
+    }\r
+}\r
+#endif /* _NS_PROVIDER_H_ */\r
diff --git a/service/notification/cpp-wrapper/consumer/src/NSConsumerService.cpp b/service/notification/cpp-wrapper/consumer/src/NSConsumerService.cpp
new file mode 100755 (executable)
index 0000000..602037c
--- /dev/null
@@ -0,0 +1,169 @@
+//******************************************************************\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
+#include "NSConsumerService.h"\r
+#include "NSProvider.h"\r
+#include "NSMessage.h"\r
+\r
+namespace OIC\r
+{\r
+    namespace Service\r
+    {\r
+        void onNSProviderDiscovered(::NSProvider *provider)\r
+        {\r
+            NS_LOG(DEBUG, "onNSProviderDiscovered - IN");\r
+            NSProvider *nsProvider = new NSProvider(provider);\r
+            if (NSConsumerService::getInstance()->getConsumerConfig().m_discoverCb != NULL)\r
+                NSConsumerService::getInstance()->getConsumerConfig().m_discoverCb(nsProvider);\r
+            delete nsProvider;\r
+            NS_LOG(DEBUG, "onNSProviderDiscovered - OUT");\r
+        }\r
+\r
+        void onNSAccepted(::NSProvider *provider)\r
+        {\r
+            NS_LOG(DEBUG, "onNSAccepted - IN");\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
+        }\r
+\r
+        void onNSMessageReceived(::NSMessage *message)\r
+        {\r
+            NS_LOG(DEBUG, "onNSMessageReceived - IN");\r
+            NSMessage *nsMessage = new NSMessage(message);\r
+            for (auto it : NSConsumerService::getInstance()->getAcceptedProviders())\r
+            {\r
+                if (it->getProviderId() == nsMessage->getProviderId())\r
+                {\r
+                    auto callback = it->getMessageReceivedCb();\r
+                    if (callback != NULL)\r
+                    {\r
+                        callback(nsMessage);\r
+                    }\r
+                    break;\r
+                }\r
+            }\r
+            delete nsMessage;\r
+            NS_LOG(DEBUG, "onNSMessageReceived - OUT");\r
+        }\r
+\r
+        void onNSSyncInfoReceived(::NSSyncInfo *syncInfo)\r
+        {\r
+            NS_LOG(DEBUG, "onNSSyncInfoReceived - IN");\r
+            NSSyncInfo *nsSyncInfo = new NSSyncInfo(syncInfo);\r
+            for (auto it : NSConsumerService::getInstance()->getAcceptedProviders())\r
+            {\r
+                if (it->getProviderId() == nsSyncInfo->getProviderId())\r
+                {\r
+                    auto callback = it->getSyncInfoReceivedCb();\r
+                    if (callback != NULL)\r
+                    {\r
+                        callback(nsSyncInfo);\r
+                    }\r
+                    break;\r
+                }\r
+            }\r
+            delete nsSyncInfo;\r
+            NS_LOG(DEBUG, "onNSSyncInfoReceived - OUT");\r
+        }\r
+\r
+        NSConsumerService::NSConsumerService()\r
+        {\r
+            m_config.m_discoverCb = NULL;\r
+            m_config.m_acceptedCb = NULL;\r
+        }\r
+\r
+        NSConsumerService::~NSConsumerService()\r
+        {\r
+            for (auto it : getAcceptedProviders())\r
+            {\r
+                delete it;\r
+            }\r
+            getAcceptedProviders().clear();\r
+        }\r
+        NSConsumerService *NSConsumerService::getInstance()\r
+        {\r
+            static  NSConsumerService s_instance;\r
+            return &s_instance;\r
+        }\r
+\r
+        void NSConsumerService::Start(NSConsumerService::ConsumerConfig config)\r
+        {\r
+            NS_LOG(DEBUG, "Start - IN");\r
+            m_config = config;\r
+            NSConsumerConfig nsConfig;\r
+            nsConfig.discoverCb = onNSProviderDiscovered;\r
+            nsConfig.acceptedCb = onNSAccepted;\r
+            nsConfig.messageCb = onNSMessageReceived;\r
+            nsConfig.syncInfoCb = onNSSyncInfoReceived;\r
+\r
+            NSStartConsumer(nsConfig);\r
+            NS_LOG(DEBUG, "Start - OUT");\r
+            return;\r
+        }\r
+\r
+        void NSConsumerService::Stop()\r
+        {\r
+            NS_LOG(DEBUG, "Stop - IN");\r
+            NSStopConsumer();\r
+            NS_LOG(DEBUG, "Stop - OUT");\r
+            return;\r
+        }\r
+\r
+        NSResult NSConsumerService::EnableRemoteService(const std::string &serverAddress)\r
+        {\r
+            NS_LOG(DEBUG, "EnableRemoteService - IN");\r
+            NSResult result = NSConsumerEnableRemoteService(OICStrdup(serverAddress.c_str()));\r
+            NS_LOG(DEBUG, "EnableRemoteService - OUT");\r
+            return result;\r
+        }\r
+\r
+        void NSConsumerService::RescanProvider()\r
+        {\r
+            NS_LOG(DEBUG, "RescanProvider - IN");\r
+            NSRescanProvider();\r
+            NS_LOG(DEBUG, "RescanProvider - OUT");\r
+            return;\r
+        }\r
+\r
+        NSProvider *NSConsumerService::getProvider(const std::string &id)\r
+        {\r
+            for (auto it : getAcceptedProviders())\r
+            {\r
+                if (it->getProviderId() == id)\r
+                    return it;\r
+            }\r
+            return NULL;\r
+        }\r
+\r
+        NSConsumerService::ConsumerConfig NSConsumerService::getConsumerConfig()\r
+        {\r
+            return m_config;\r
+        }\r
+\r
+        std::list<NSProvider *> NSConsumerService::getAcceptedProviders()\r
+        {\r
+            return m_acceptedProviders;\r
+        }\r
+    }\r
+}\r
diff --git a/service/notification/cpp-wrapper/consumer/src/NSProvider.cpp b/service/notification/cpp-wrapper/consumer/src/NSProvider.cpp
new file mode 100755 (executable)
index 0000000..31d7e52
--- /dev/null
@@ -0,0 +1,90 @@
+//******************************************************************\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
+#include "NSProvider.h"\r
+#include "NSConsumerInterface.h"\r
+\r
+namespace OIC\r
+{\r
+    namespace Service\r
+    {\r
+        ::NSProvider *NSProvider::getNSProvider()\r
+        {\r
+            ::NSProvider *provider = new ::NSProvider;\r
+            OICStrcpy(provider->providerId, m_providerId.length(), m_providerId.c_str());\r
+            return provider;\r
+        }\r
+\r
+        NSProvider::NSProvider(::NSProvider *provider)\r
+        {\r
+            m_messageCb = NULL;\r
+            m_syncInfoCb = NULL;\r
+            if (provider != nullptr)\r
+            {\r
+                if ((provider->providerId != nullptr) && strlen(provider->providerId))\r
+                    m_providerId.assign(provider->providerId, strlen(provider->providerId));\r
+            }\r
+        }\r
+\r
+        std::string NSProvider::getProviderId() const\r
+        {\r
+            return m_providerId;\r
+        }\r
+\r
+        void NSProvider::subscribe()\r
+        {\r
+            NS_LOG(DEBUG, "subscribe - IN");\r
+            NSSubscribe(getNSProvider());\r
+            NS_LOG(DEBUG, "subscribe - OUT");\r
+        }\r
+\r
+        void NSProvider::unSubscribe()\r
+        {\r
+            NS_LOG(DEBUG, "unSubscribe - IN");\r
+            NSUnsubscribe(getNSProvider());\r
+            NS_LOG(DEBUG, "unSubscribe - OUT");\r
+        }\r
+\r
+        void NSProvider::SendSyncInfo(uint64_t messageId, NSSyncInfo::NSSyncType type)\r
+        {\r
+            NS_LOG(DEBUG, "SendSyncInfo - IN");\r
+            NSConsumerSendSyncInfo(m_providerId.c_str(), messageId, (::NSSyncType)type);\r
+            NS_LOG(DEBUG, "SendSyncInfo - OUT");\r
+            return;\r
+        }\r
+\r
+        void NSProvider::setListener(NSProvider::MessageReceivedCallback messageHandle,\r
+                                     NSProvider::SyncInfoReceivedCallback syncHandle)\r
+        {\r
+            m_messageCb = messageHandle;\r
+            m_syncInfoCb = syncHandle;\r
+        }\r
+\r
+        NSProvider::MessageReceivedCallback NSProvider::getMessageReceivedCb()\r
+        {\r
+            return m_messageCb;\r
+        }\r
+\r
+        NSProvider::SyncInfoReceivedCallback NSProvider::getSyncInfoReceivedCb()\r
+        {\r
+            return m_syncInfoCb;\r
+        }\r
+    }\r
+}\r
diff --git a/service/notification/cpp-wrapper/examples/linux/SConscript b/service/notification/cpp-wrapper/examples/linux/SConscript
new file mode 100755 (executable)
index 0000000..96d8f35
--- /dev/null
@@ -0,0 +1,59 @@
+##
+# Notification build script
+##
+
+Import('env')
+
+lib_env = env.Clone()
+SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env')
+notification_sample_env = lib_env.Clone()
+
+target_os = env.get('TARGET_OS')
+######################################################################
+# Build flags
+######################################################################
+notification_sample_env.AppendUnique(CPPPATH = ['../../../include'])
+notification_sample_env.AppendUnique(CPPPATH = ['../../provider/inc'])
+notification_sample_env.AppendUnique(CPPPATH = ['../../consumer/inc'])
+notification_sample_env.AppendUnique(CPPPATH = ['../../common'])
+notification_sample_env.AppendUnique(CPPPATH = ['../../../../../resource/csdk/stack/include'])
+notification_sample_env.AppendUnique(CPPPATH = ['../../../../../resource/csdk/connectivity/api'])
+notification_sample_env.AppendUnique(CPPPATH = ['../../../src/common'])
+
+notification_sample_env.PrependUnique(LIBS = [
+       'liboctbstack',
+       'oc_logger',
+       'connectivity_abstraction',
+       'libcoap'
+       ])
+
+if target_os not in ['windows', 'winrt']:
+       notification_sample_env.AppendUnique(CXXFLAGS = ['-O2', '-g', '-Wall', '-fmessage-length=0', '-std=c++0x'])
+
+if target_os not in ['darwin', 'ios', 'windows', 'winrt']:
+       notification_sample_env.AppendUnique(LINKFLAGS = ['-Wl,--no-undefined'])
+
+if target_os == 'linux':
+       notification_sample_env.AppendUnique(LIBS = ['pthread'])
+
+if target_os == 'android':
+       notification_sample_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
+       notification_sample_env.AppendUnique(LIBS = ['gnustl_shared','log'])
+
+       if not env.get('RELEASE'):
+               notification_sample_env.AppendUnique(LIBS = ['log'])
+####################################################################
+# Source files and Targets
+######################################################################
+notification_sample_provider_env = notification_sample_env.Clone()
+
+notification_sample_provider_env.AppendUnique(LIBS = 'libnotification_provider_wrapper')
+notification_sample_provider_env.AppendUnique(LIBS = 'libnotification_provider')
+notificationproviderwrapper = notification_sample_provider_env.Program('notificationproviderwrapper', 'notificationserviceprovider.cpp')
+i_notificationprovider = notification_sample_provider_env.Install(env.get('BUILD_DIR'), notificationproviderwrapper)
+
+notification_sample_consumer_env = notification_sample_env.Clone()
+notification_sample_consumer_env.AppendUnique(LIBS = 'libnotification_consumer_wrapper')
+notification_sample_consumer_env.AppendUnique(LIBS = 'libnotification_consumer')
+notificationconsumerwrapper = notification_sample_consumer_env.Program('notificationconsumerwrapper', 'notificationserviceconsumer.cpp')
+i_notificationconsumer = notification_sample_consumer_env.Install(env.get('BUILD_DIR'), notificationconsumerwrapper)
diff --git a/service/notification/cpp-wrapper/examples/linux/notificationserviceconsumer.cpp b/service/notification/cpp-wrapper/examples/linux/notificationserviceconsumer.cpp
new file mode 100755 (executable)
index 0000000..b804a59
--- /dev/null
@@ -0,0 +1,138 @@
+/******************************************************************\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
+#include <iostream>\r
+\r
+#include <unistd.h>\r
+#include "NSConsumerService.h"\r
+#include "NSMessage.h"\r
+#include "NSProvider.h"\r
+#include "ocstack.h"\r
+\r
+#define TAG "NotiConsumerWrapperExample"\r
+using namespace std;\r
+using namespace OIC::Service;\r
+\r
+bool isExit = false;\r
+std::string REMOTE_SERVER_ADDRESS;\r
+\r
+void onNotificationPostedCb(OIC::Service::NSMessage *notification)\r
+{\r
+    std::cout << "id : " << notification->getMessageId() << std::endl;\r
+    std::cout << "title : " << notification->getTitle() << std::endl;\r
+    std::cout << "content : " <<  notification->getContentText() << std::endl;\r
+    std::cout << "source : " <<  notification->getSourceName() << std::endl;\r
+}\r
+\r
+void onNotificationSyncCb(OIC::Service::NSSyncInfo *sync)\r
+{\r
+    std::cout << "Sync ID : " <<  sync->getMessageId() << std::endl;\r
+    std::cout << "Sync STATE : " << (int) sync->getState() << std::endl;\r
+}\r
+\r
+void onDiscoverNotificationCb(OIC::Service::NSProvider *provider)\r
+{\r
+    std::cout << "notification resource discovered" << std::endl;\r
+    provider->subscribe();\r
+    std::cout << "startSubscribing" << std::endl;\r
+}\r
+\r
+void onSubscriptionAcceptedCb(OIC::Service::NSProvider *provider)\r
+{\r
+    std::cout << "Subscription accepted" << std::endl;\r
+    std::cout << "subscribed provider Id : " << provider->getProviderId() << std::endl;\r
+    provider->setListener(onNotificationPostedCb, onNotificationSyncCb);\r
+}\r
+\r
+void *OCProcessThread(void *ptr)\r
+{\r
+    (void) ptr;\r
+\r
+    while (!isExit)\r
+    {\r
+        usleep(2000);\r
+        if (OCProcess() != OC_STACK_OK)\r
+        {\r
+            OCStop();\r
+            break;\r
+        }\r
+    }\r
+\r
+    return NULL;\r
+}\r
+\r
+int main(void)\r
+{\r
+    pthread_t OCThread;\r
+\r
+    std::cout << "start Iotivity" << std::endl;\r
+    if (OCInit1(OC_CLIENT, OC_DEFAULT_FLAGS, OC_DEFAULT_FLAGS) != OC_STACK_OK)\r
+    {\r
+        std::cout << "OCInit fail" << std::endl;\r
+        return 0;\r
+    }\r
+\r
+    NSConsumerService::ConsumerConfig cfg;\r
+    cfg.m_discoverCb = onDiscoverNotificationCb;\r
+    cfg.m_acceptedCb = onSubscriptionAcceptedCb;\r
+\r
+    pthread_create(&OCThread, NULL, OCProcessThread, NULL);\r
+\r
+    std::cout << "Start notification consumer service" << std::endl;\r
+    while (!isExit)\r
+    {\r
+        int num;\r
+\r
+        std::cout << "1. Start Consumer" << std::endl;\r
+        std::cout << "2. Stop Consumer" << std::endl;\r
+        std::cout << "3. Enable  NS Consumer RemoteService" << std::endl;\r
+        std::cout << "5. Exit" << std::endl;\r
+\r
+        std::cout << "Input: " << std::endl;\r
+        std::cin >> num;\r
+        switch (num)\r
+        {\r
+            case 1:\r
+                std::cout << "1. Start the Notification Consumer" << std::endl;\r
+                NSConsumerService::getInstance()->Start(cfg);\r
+                break;\r
+            case 2:\r
+                std::cout << "2. Stop the Notification Consumer" << std::endl;\r
+                NSConsumerService::getInstance()->Stop();\r
+                break;\r
+            case 3:\r
+                {\r
+                    std::cout << "3. Enable NS Consumer RemoteService" << std::endl;\r
+                    std::cout << "Input the Server Address :";\r
+                    std::cin >> REMOTE_SERVER_ADDRESS;\r
+                    NSConsumerService::getInstance()->EnableRemoteService(REMOTE_SERVER_ADDRESS);\r
+                    break;\r
+                }\r
+            case 5:\r
+                std::cout << "5. Exit" << std::endl;\r
+                isExit = true;\r
+                break;\r
+            default:\r
+                break;\r
+        }\r
+    }\r
+\r
+    return 0;\r
+}\r
diff --git a/service/notification/cpp-wrapper/examples/linux/notificationserviceprovider.cpp b/service/notification/cpp-wrapper/examples/linux/notificationserviceprovider.cpp
new file mode 100755 (executable)
index 0000000..9f55712
--- /dev/null
@@ -0,0 +1,192 @@
+/******************************************************************\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
+#include <iostream>\r
+#include <stdlib.h>\r
+#include "NSCommon.h"\r
+#include "NSProviderService.h"\r
+#include "logger.h"\r
+#include "octypes.h"\r
+#include "pthread.h"\r
+#include "oic_string.h"\r
+#include "oic_malloc.h"\r
+#include "ocstack.h"\r
+\r
+#define TAG "NotiProviderWrapperExample"\r
+using namespace std;\r
+using namespace OIC::Service;\r
+\r
+extern char *strdup(const char *s);\r
+\r
+bool isExit = false;\r
+\r
+int id = 0;\r
+std::string REMOTE_SERVER_ADDRESS;\r
+\r
+void *OCProcessThread(void *ptr)\r
+{\r
+    (void) ptr;\r
+    while (!isExit)\r
+    {\r
+        if (OCProcess() != OC_STACK_OK)\r
+        {\r
+            std::cout << "OCStack process error" << std::endl;\r
+            return NULL;\r
+        }\r
+    }\r
+\r
+    return NULL;\r
+}\r
+\r
+void subscribeRequestCallback(OIC::Service::NSConsumer *consumer)\r
+{\r
+    std::cout << "consumer requested to subscribe" << std::endl;\r
+\r
+    std::cout << "Consumer Device ID: " << consumer->getConsumerId() << std::endl;\r
+    consumer->acceptSubscription(consumer, true);\r
+}\r
+\r
+void syncCallback(OIC::Service::NSSyncInfo *sync)\r
+{\r
+    std::cout << "synnc requested" << std::endl;\r
+\r
+    std::cout << "Sync State: " << (int) sync->getState() << std::endl;\r
+}\r
+\r
+int main()\r
+{\r
+    int num;\r
+    pthread_t processThread;\r
+\r
+    std::cout << "start Iotivity" << std::endl;\r
+\r
+\r
+    if (OCInit(NULL, 0, OC_CLIENT_SERVER) != OC_STACK_OK)\r
+    {\r
+        std::cout << "OCStack init error" << std::endl;\r
+        return 0;\r
+    }\r
+\r
+    pthread_create(&processThread, NULL, OCProcessThread, NULL);\r
+\r
+    while (!isExit)\r
+    {\r
+        std::cout << "1. Start the Notification Provider(Accepter: Provider)" << std::endl;\r
+        std::cout << "2. Start the Notification Provider(Accepter: Consumer)" << std::endl;\r
+        std::cout << "3. SendMessage " << std::endl;\r
+        std::cout << "4. SendSyncInfo" << std::endl;\r
+        std::cout << "5. Enable NS Provider RemoteService" << std::endl;\r
+        std::cout << "6. Disable NS Provider RemoteService" << std::endl;\r
+        std::cout << "9. Stop the Notification Provider" << std::endl;\r
+        std::cout << "0. Exit()" << std::endl;\r
+\r
+        std::cout << "input : ";\r
+\r
+        std::cin >> num;\r
+\r
+        switch (num)\r
+        {\r
+            case 1:\r
+                {\r
+                    std::cout << "Start (Accepter: Provider)" << std::endl;\r
+                    NSProviderService::ProviderConfig cfg;\r
+                    cfg.m_subscribeRequestCb = subscribeRequestCallback;\r
+                    cfg.m_syncInfoCb = syncCallback;\r
+                    NSProviderService::getInstance()->Start(NSProviderService::NSAccessPolicy::NS_ACCESS_ALLOW, cfg);\r
+                    break;\r
+                }\r
+            case 2:\r
+                {\r
+                    std::cout << "Start (Accepter: Consumer)" << std::endl;\r
+                    NSProviderService::ProviderConfig cfg;\r
+                    cfg.m_subscribeRequestCb = subscribeRequestCallback;\r
+                    cfg.m_syncInfoCb = syncCallback;\r
+                    NSProviderService::getInstance()->Start(NSProviderService::NSAccessPolicy::NS_ACCESS_DENY, cfg);\r
+                    break;\r
+                }\r
+            case 3:\r
+                {\r
+                    std::cout << "SendMessage" << std::endl;\r
+\r
+                    std::string title;\r
+                    std::string body;\r
+\r
+                    std::cout << "id : " << ++id << std::endl;\r
+                    std::cout << "title : ";\r
+\r
+                    std::cin >> title;\r
+\r
+                    std::cout << "body : ";\r
+                    std::cin >> body;\r
+\r
+                    std::cout << "app - mTitle : " << title << std::endl;\r
+                    std::cout << "app - mContentText : " << body << std::endl;\r
+\r
+                    OIC::Service::NSMessage *msg = new OIC::Service::NSMessage();\r
+                    msg->setType(OIC::Service::NSMessage::NSMessageType::NS_MESSAGE_INFO);\r
+                    msg->setTitle(title.c_str());\r
+                    msg->setContentText(body.c_str());\r
+                    msg->setTime("");\r
+                    msg->setTTL(0);\r
+                    msg->setSourceName("OCF");\r
+\r
+                    NSProviderService::getInstance()->SendMessage(msg);\r
+\r
+                    break;\r
+                }\r
+            case 4:\r
+                {\r
+                    std::cout <<  "SendSyncInfo" << std::endl;\r
+                    NSProviderService::getInstance()->SendSyncInfo(1,\r
+                            OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ);\r
+                    break;\r
+                }\r
+            case 5:\r
+                {\r
+                    std::cout << "3. Enable NS Provider RemoteService" << std::endl;\r
+                    std::cout << "Input the Server Address :";\r
+                    std::cin >> REMOTE_SERVER_ADDRESS;\r
+                    NSProviderService::getInstance()->EnableRemoteService(REMOTE_SERVER_ADDRESS);\r
+                    break;\r
+                }\r
+            case 6:\r
+                {\r
+                    std::cout << "3. Disable NS Provider RemoteService" << std::endl;\r
+                    std::cout << "Input the Server Address :";\r
+                    NSProviderService::getInstance()->DisableRemoteService(REMOTE_SERVER_ADDRESS);\r
+                    break;\r
+                }\r
+            case 9:\r
+                NSProviderService::getInstance()->Stop();\r
+                break;\r
+            case 0:\r
+                NSProviderService::getInstance()->Stop();\r
+                isExit = true;\r
+                break;\r
+            default:\r
+                std::cout << "Under Construction" << std::endl;\r
+                break;\r
+        }\r
+\r
+        std::cout << std::endl;\r
+    }\r
+\r
+    return 0;\r
+}\r
diff --git a/service/notification/cpp-wrapper/provider/SConscript b/service/notification/cpp-wrapper/provider/SConscript
new file mode 100755 (executable)
index 0000000..92b58b9
--- /dev/null
@@ -0,0 +1,70 @@
+#******************************************************************
+#
+# 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.
+#
+#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+##
+# Notification Service c++ wrapper build script
+##
+
+import platform
+Import('env')
+
+if env.get('RELEASE'):
+       env.AppendUnique(CCFLAGS = ['-Os'])
+       env.AppendUnique(CPPDEFINES = ['NDEBUG'])
+else:
+       env.AppendUnique(CCFLAGS = ['-g'])
+
+if env.get('LOGGING'):
+       env.AppendUnique(CPPDEFINES = ['TB_LOG'])
+
+lib_env = env.Clone()
+SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env')
+notification_env = lib_env.Clone()
+
+target_os = env.get('TARGET_OS')
+
+######################################################################
+# Build flags
+######################################################################
+notification_env.AppendUnique(CPPPATH = ['../../include'])
+notification_env.AppendUnique(CPPPATH = ['inc'])
+notification_env.AppendUnique(CPPPATH = ['../common'])
+notification_env.AppendUnique(CPPPATH = ['../consumer/inc'])
+notification_env.AppendUnique(CPPPATH = ['../../src/common'])
+
+notification_env.PrependUnique(LIBS = [
+       'oc_logger',
+       'libnotification_provider'
+       ])
+notification_env.AppendUnique(CXXFLAGS = ['-O2', '-Wall', '-fmessage-length=0', '-std=c++0x','-frtti'])
+if target_os == 'android':
+    notification_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
+    notification_env.PrependUnique(LIBS = ['gnustl_shared', 'log'])
+
+######################################################################
+# Source files and Targets
+######################################################################
+
+notification_provider_src = [
+       env.Glob('src/*.cpp'),env.Glob('../common/*.cpp')]
+
+providersdk = notification_env.SharedLibrary('notification_provider_wrapper', notification_provider_src)
+notification_env.InstallTarget(providersdk, 'libnotification_provider_wrapper')
+notification_env.UserInstallTargetLib(providersdk, 'libnotification_provider_wrapper')
diff --git a/service/notification/cpp-wrapper/provider/inc/NSConsumer.h b/service/notification/cpp-wrapper/provider/inc/NSConsumer.h
new file mode 100755 (executable)
index 0000000..cae98c0
--- /dev/null
@@ -0,0 +1,96 @@
+//******************************************************************\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 Consumer representation.\r
+ */\r
+\r
+#ifndef _NS_CONSUMER_H_\r
+#define _NS_CONSUMER_H_\r
+\r
+\r
+#include <string>\r
+#include <cstring>\r
+#include "NSCommon.h"\r
+#include "oic_string.h"\r
+#include "NSConstants.h"\r
+\r
+namespace OIC\r
+{\r
+    namespace Service\r
+    {\r
+        /**\r
+         * @class   NSConsumer\r
+         * @brief   This class provides a set of Notification service Consumer representation APIs.\r
+         */\r
+        class NSConsumer\r
+        {\r
+            public:\r
+                /**\r
+                      * Constructor of NSConsumer.\r
+                      */\r
+                NSConsumer() = default;\r
+\r
+                /**\r
+                      * Constructor of NSConsumer.\r
+                      *\r
+                      * @param consumerId - consumerId of the Notification service Consumer.\r
+                      */\r
+                NSConsumer(const std::string &consumerId)\r
+                    : m_consumerId(consumerId) {}\r
+\r
+                /**\r
+                      * Constructor of NSConsumer.\r
+                      *\r
+                      * @param consumer - NSConsumer struct to initialize.\r
+                      */\r
+                NSConsumer(::NSConsumer *consumer);\r
+\r
+                /**\r
+                      * Destructor of NSConsumer.\r
+                      */\r
+                ~NSConsumer() = default;\r
+\r
+                /**\r
+                      * This method is for getting ConsumerId from the Notification service Consumer.\r
+                      *\r
+                      * @return ConsumerId as string.\r
+                      */\r
+                std::string getConsumerId() const;\r
+\r
+                /**\r
+                      * This method is for setting icon image for the Notification service media contents.\r
+                      *\r
+                      * @param consumer - NSConsumer.\r
+                      * @param accepted - as bool.\r
+                      */\r
+                int acceptSubscription(NSConsumer *consumer, bool accepted);\r
+\r
+            private:\r
+                ::NSConsumer *getNSConsumer();\r
+\r
+            private:\r
+                std::string m_consumerId;\r
+        };\r
+    }\r
+}\r
+#endif /* _NS_CONSUMER_H_ */\r
diff --git a/service/notification/cpp-wrapper/provider/inc/NSProviderService.h b/service/notification/cpp-wrapper/provider/inc/NSProviderService.h
new file mode 100755 (executable)
index 0000000..d98d31e
--- /dev/null
@@ -0,0 +1,164 @@
+//******************************************************************\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 provides C++ Wrapper APIs of Notification Service for Provider.\r
+ */\r
+\r
+#ifndef _NS_PROVIDER_SERVICE_H_\r
+#define _NS_PROVIDER_SERVICE_H_\r
+\r
+#include "NSCommon.h"\r
+#include "NSProviderInterface.h"\r
+#include "NSMessage.h"\r
+#include "oic_string.h"\r
+#include "NSConsumer.h"\r
+#include "NSSyncInfo.h"\r
+#include "NSConstants.h"\r
+#include <cstring>\r
+\r
+namespace OIC\r
+{\r
+    namespace Service\r
+    {\r
+        /**\r
+         * @class   NSProviderService\r
+         * @brief   This class provides a set of C++APIs for Notification Provider.\r
+         */\r
+        class NSProviderService\r
+        {\r
+\r
+            public:\r
+                /**\r
+                      * Provider uses this callback function to receive subscription request of consumer\r
+                      * @param[in] consumer        Consumer who subscribes the resource\r
+                      */\r
+                typedef void (*ConsumerSubscribedCallback)(NSConsumer *);\r
+\r
+                /**\r
+                      * Provider use this callback function to receive the status of the message\r
+                      * synchronization\r
+                      * @param[in] sync        Synchronization information of the notification message\r
+                      */\r
+                typedef void (*MessageSynchronizedCallback)(NSSyncInfo *);\r
+\r
+\r
+                /**\r
+                      * @struct   ProviderConfig\r
+                      * @brief Provider sets this callback function configuration for registering callbacks\r
+                      *\r
+                      */\r
+                typedef struct\r
+                {\r
+                    /** m_subscribeRequestCb - ConsumerSubscribedCallback callback listener.*/\r
+                    ConsumerSubscribedCallback m_subscribeRequestCb;\r
+                    /** m_syncInfoCb - MessageSynchronizedCallback callback listener.*/\r
+                    MessageSynchronizedCallback m_syncInfoCb;\r
+                } ProviderConfig;\r
+\r
+                /**\r
+                     * Access policy exchanged between provider and consumer during subscription process\r
+                     */\r
+                enum class NSAccessPolicy\r
+                {\r
+                    NS_ACCESS_ALLOW = 0,\r
+                    NS_ACCESS_DENY = 1,\r
+                };\r
+\r
+                /**\r
+                      * API for starting the NS Provider\r
+                      *\r
+                      * @return NSProviderService Pointer to singleton instance created\r
+                      */\r
+                static NSProviderService *getInstance();\r
+\r
+                /**\r
+                      * Initialize notification service for provider\r
+                      * @param[in]  policy   Accepter\r
+                      * @param[in]  config   ProviderConfig Callback function pointers to onConsumerSubscribed,\r
+                      * and onMessageSynchronized function listeners\r
+                      * @return :: result code of NSResult\r
+                      */\r
+                NSResult Start(NSAccessPolicy policy, ProviderConfig config);\r
+\r
+                /**\r
+                      * Terminate notification service for provider\r
+                      * @return :: result code of NSResult\r
+                      */\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 NSResult\r
+                      */\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 NSResult\r
+                      */\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 NSResult\r
+                      */\r
+                NSResult SendMessage(NSMessage *msg);\r
+\r
+\r
+                /**\r
+                      * Send read-check to provider in order to synchronize notification status with other consumers\r
+                      * @param[in]  messageId  Notification message to synchronize the status\r
+                      * @param[in]  type  NotificationSyncType of the SyncInfo message\r
+                      * @return :: result code of NSResult\r
+                      */\r
+                void SendSyncInfo(uint64_t messageId, NSSyncInfo::NSSyncType type);\r
+\r
+                /**\r
+                      *  get Provider config values\r
+                      * @return ProviderConfig callbaks set\r
+                      */\r
+                ProviderConfig getProviderConfig();\r
+\r
+            private :\r
+                ProviderConfig m_config;\r
+\r
+            private:\r
+                NSProviderService()\r
+                {\r
+                    m_config.m_subscribeRequestCb = NULL;\r
+                    m_config.m_syncInfoCb = NULL;\r
+                }\r
+                ~NSProviderService() = default;\r
+                NSProviderService(const NSProviderService &) = delete;\r
+                NSProviderService &operator=(const NSProviderService &) = delete;\r
+                NSProviderService(const NSProviderService &&) = delete;\r
+                NSProviderService &operator=(const NSProviderService && ) = delete;\r
+\r
+                ::NSMessage *getNSMessage(NSMessage *msg);\r
+        };\r
+    }\r
+}\r
+#endif /* _NS_PROVIDER_SERVICE_H_ */\r
diff --git a/service/notification/cpp-wrapper/provider/src/NSConsumer.cpp b/service/notification/cpp-wrapper/provider/src/NSConsumer.cpp
new file mode 100755 (executable)
index 0000000..9fce017
--- /dev/null
@@ -0,0 +1,58 @@
+//******************************************************************\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
+#include "NSConsumer.h"\r
+#include "NSProviderInterface.h"\r
+\r
+namespace OIC\r
+{\r
+    namespace Service\r
+    {\r
+        ::NSConsumer *NSConsumer::getNSConsumer()\r
+        {\r
+            ::NSConsumer *nsCon = new ::NSConsumer;\r
+            OICStrcpy(nsCon->consumerId, m_consumerId.length(), m_consumerId.c_str());\r
+            return nsCon;\r
+        }\r
+\r
+        NSConsumer::NSConsumer(::NSConsumer *consumer)\r
+        {\r
+            if (consumer != nullptr)\r
+            {\r
+                if ((consumer->consumerId != nullptr) && strlen(consumer->consumerId))\r
+                    m_consumerId.assign(consumer->consumerId, strlen(consumer->consumerId));\r
+            }\r
+        }\r
+\r
+        std::string NSConsumer::getConsumerId() const\r
+        {\r
+            return m_consumerId;\r
+        }\r
+\r
+        int NSConsumer::acceptSubscription(NSConsumer *consumer, bool accepted)\r
+        {\r
+            NS_LOG(DEBUG, "acceptSubscription - IN");\r
+            if (consumer != nullptr)\r
+                return NSAccept(consumer->getNSConsumer(), accepted);\r
+            NS_LOG(DEBUG, "acceptSubscription - OUT");\r
+            return NS_ERROR;\r
+        }\r
+    }\r
+}\r
diff --git a/service/notification/cpp-wrapper/provider/src/NSProviderService.cpp b/service/notification/cpp-wrapper/provider/src/NSProviderService.cpp
new file mode 100755 (executable)
index 0000000..6514d85
--- /dev/null
@@ -0,0 +1,136 @@
+//******************************************************************\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
+#include "NSProviderService.h"\r
+\r
+namespace OIC\r
+{\r
+    namespace Service\r
+    {\r
+        void onConsumerSubscribedCallback(::NSConsumer *consumer)\r
+        {\r
+            NS_LOG(DEBUG, "onConsumerSubscribedCallback - IN");\r
+            NSConsumer *nsConsumer = new NSConsumer(consumer);\r
+            if (NSProviderService::getInstance()->getProviderConfig().m_subscribeRequestCb != NULL)\r
+                NSProviderService::getInstance()->getProviderConfig().m_subscribeRequestCb(nsConsumer);\r
+            delete nsConsumer;\r
+            NS_LOG(DEBUG, "onConsumerSubscribedCallback - OUT");\r
+        }\r
+\r
+        void onMessageSynchronizedCallback(::NSSyncInfo *syncInfo)\r
+        {\r
+            NS_LOG(DEBUG, "onMessageSynchronizedCallback - IN");\r
+            NSSyncInfo *nsSyncInfo = new NSSyncInfo(syncInfo);\r
+            if (NSProviderService::getInstance()->getProviderConfig().m_syncInfoCb != NULL)\r
+                NSProviderService::getInstance()->getProviderConfig().m_syncInfoCb(nsSyncInfo);\r
+            delete nsSyncInfo;\r
+            NS_LOG(DEBUG, "onMessageSynchronizedCallback - OUT");\r
+        }\r
+\r
+        ::NSMessage *NSProviderService::getNSMessage(NSMessage *msg)\r
+        {\r
+            ::NSMessage *nsMsg = new ::NSMessage;\r
+            nsMsg->messageId = msg->getMessageId();\r
+            OICStrcpy(nsMsg->providerId, msg->getProviderId().length(), msg->getProviderId().c_str());\r
+            nsMsg->sourceName = OICStrdup(msg->getSourceName().c_str());\r
+            nsMsg->type = (::NSMessageType) msg->getType();\r
+            nsMsg->dateTime = OICStrdup(msg->getTime().c_str());\r
+            nsMsg->ttl = msg->getTTL();\r
+            nsMsg->title = OICStrdup(msg->getTitle().c_str());\r
+            nsMsg->contentText = OICStrdup(msg->getContentText().c_str());\r
+\r
+            nsMsg->mediaContents = new ::NSMediaContents;\r
+            if (msg->getMediaContents() != nullptr)\r
+                nsMsg->mediaContents->iconImage = OICStrdup(msg->getMediaContents()->getIconImage().c_str());\r
+            else\r
+                nsMsg->mediaContents->iconImage = nullptr;\r
+            return nsMsg;\r
+        }\r
+\r
+        NSProviderService *NSProviderService::getInstance()\r
+        {\r
+            static NSProviderService s_instance;\r
+            return &s_instance;\r
+        }\r
+\r
+        NSResult NSProviderService::Start(NSProviderService::NSAccessPolicy policy,\r
+                                          NSProviderService::ProviderConfig config)\r
+        {\r
+            NS_LOG(DEBUG, "Start - IN");\r
+\r
+            m_config = config;\r
+            NSResult result = NSStartProvider((::NSAccessPolicy)policy, onConsumerSubscribedCallback,\r
+                                              onMessageSynchronizedCallback);\r
+            NS_LOG(DEBUG, "Start - OUT");\r
+            return result;\r
+        }\r
+\r
+        NSResult NSProviderService::Stop()\r
+        {\r
+            NS_LOG(DEBUG, "Stop - IN");\r
+            NSResult result = NSStopProvider();\r
+            NS_LOG(DEBUG, "Stop - OUT");\r
+            return result;\r
+        }\r
+\r
+        NSResult NSProviderService::EnableRemoteService(const std::string &serverAddress)\r
+        {\r
+            NS_LOG(DEBUG, "EnableRemoteService - IN");\r
+            NSResult result = NSProviderEnableRemoteService(OICStrdup(serverAddress.c_str()));\r
+            NS_LOG(DEBUG, "EnableRemoteService - OUT");\r
+            return result;\r
+        }\r
+\r
+        NSResult NSProviderService::DisableRemoteService(const std::string &serverAddress)\r
+        {\r
+            NS_LOG(DEBUG, "DisableRemoteService - IN");\r
+            NSResult result = NSProviderDisableRemoteService(OICStrdup(serverAddress.c_str()));\r
+            NS_LOG(DEBUG, "DisableRemoteService - OUT");\r
+            return result;\r
+        }\r
+\r
+        NSResult NSProviderService::SendMessage(NSMessage *msg)\r
+        {\r
+            NS_LOG(DEBUG, "SendMessage - IN");\r
+            NSResult result = NS_ERROR;\r
+            if (msg != nullptr)\r
+                result = NSSendMessage(getNSMessage(msg));\r
+            else\r
+                NS_LOG(DEBUG, "Empty Message");\r
+            NS_LOG(DEBUG, "SendMessage - OUT");\r
+            return result;\r
+        }\r
+\r
+        void NSProviderService::SendSyncInfo(uint64_t messageId,\r
+                                             NSSyncInfo::NSSyncType type)\r
+        {\r
+            NS_LOG(DEBUG, "SendSyncInfo - IN");\r
+            NSProviderSendSyncInfo(messageId, (NSSyncType)type);\r
+            NS_LOG(DEBUG, "SendSyncInfo - OUT");\r
+            return;\r
+        }\r
+\r
+        NSProviderService::ProviderConfig NSProviderService::getProviderConfig()\r
+        {\r
+            return m_config;\r
+        }\r
+    }\r
+}\r