replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / service / notification / src / consumer / NSConsumerCommon.h
index ba593be..2100b22 100644 (file)
@@ -18,8 +18,8 @@
 //
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
-#ifndef _NS_CONSUMER_CONSTANTS_H_
-#define _NS_CONSUMER_CONSTANTS_H_
+#ifndef _NS_CONSUMER_COMMON_H_
+#define _NS_CONSUMER_COMMON_H_
 
 #ifdef __cplusplus
 extern "C" {
@@ -32,148 +32,75 @@ extern "C" {
 #include "NSStructs.h"
 #include "ocstack.h"
 
-#define NS_QOS OC_LOW_QOS
-#define NS_RESOURCE_TYPE "oic.r.notification"
+#define NS_QOS OC_HIGH_QOS
+#define NS_RESOURCE_TYPE "x.org.iotivity.notification"
 #define NS_RESOURCE_URI "/notification"
 #define NS_INTERFACE_BASELINE "oic.if.baseline"
-#define NS_INTERFACE_NOTIFICATION "oic.if.notification"
 #define NS_RESOURCE_QUERY "/oic/res"
 
-#define NS_DISCOVER_QUERY "/oic/res?rt=oic.r.notification"
+#define NS_DISCOVER_QUERY "/oic/res?rt=x.org.iotivity.notification"
 #define NS_DEVICE_ID_LENGTH 37
 
-#define NS_VERIFY_NOT_NULL_V(obj) \
-    { \
-        if ((obj) == NULL) \
-        { \
-            NS_LOG_V(ERROR, "%s : %s is null", __func__, #obj); \
-            return; \
-        } \
-    }
-
-#define NS_VERIFY_NOT_NULL(obj, retVal) \
-    { \
-        if ((obj) == NULL) \
-        { \
-            NS_LOG_V(ERROR, "%s : %s is null", __func__, #obj); \
-            return (retVal); \
-        } \
-    }
-
-#define NS_VERIFY_NOT_NULL_WITH_POST_CLEANING_V(obj, func) \
-    { \
-        if ((obj) == NULL) \
-        { \
-            NS_LOG_V(ERROR, "%s : %s is null", __func__, #obj); \
-            NS_LOG(ERROR, "execute deletion"); \
-            (func); \
-            return; \
-        } \
-    }
-
-#define NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(obj, retVal, func) \
-    { \
-        if ((obj) == NULL) \
-        { \
-            NS_LOG_V(ERROR, "%s : %s is null", __func__, #obj); \
-            NS_LOG(ERROR, "execute deletion"); \
-            (func); \
-            return (retVal); \
-        } \
-    }
-
-#define NS_VERIFY_STACK_OK_V(obj) \
-    { \
-        OCStackResult _ret = (obj); \
-        if ( _ret != OC_STACK_OK) \
-        { \
-            NS_LOG_V(ERROR, "%s : %s is not OC_STACK_OK : %d", __func__, #obj, _ret); \
-            return; \
-        } \
-    }
-
-#define NS_VERIFY_STACK_OK(obj, retVal) \
-    { \
-        OCStackResult _ret = (obj); \
-        if ( _ret != OC_STACK_OK) \
-        { \
-            NS_LOG_V(ERROR, "%s : %s is not OC_STACK_OK : %d", __func__, #obj, _ret); \
-            return (retVal); \
-        } \
-    }
-
-#define NS_VERIFY_STACK_OK_WITH_POST_CLEANING(obj, retVal, func) \
-    { \
-        OCStackResult _ret = (obj); \
-        if ( _ret != OC_STACK_OK) \
-        { \
-            NS_LOG_V(ERROR, "%s : %s is not OC_STACK_OK : %d", __func__, #obj, _ret); \
-            (func); \
-            return (retVal); \
-        } \
-    }
-
-#define NSOICFree(obj) \
-    { \
-        if ((obj)) \
-        { \
-            OICFree((obj)); \
-            (obj) = NULL; \
-            NS_LOG_V(DEBUG, "%s : %s Removed", __func__, #obj); \
-        } \
-    }
+typedef enum
+{
+    NS_DISCOVER_DEFAULT, // will work for adapter_ip.
+    NS_DISCOVER_UDP,
+    NS_DISCOVER_TCP,
+    NS_DISCOVER_CLOUD
+} NSConsumerDiscoverType;
 
-typedef struct
+typedef enum
 {
-    char providerId[NS_DEVICE_ID_LENGTH];
+    NS_SELECTION_CONSUMER = 0,
+    NS_SELECTION_PROVIDER = 1
+} NSSelector;
 
-    char * messageUri;
-    char * syncUri;
+typedef struct NSProviderConnectionInfo
+{
+    OCDevAddr * addr;
 
     OCDoHandle messageHandle;
     OCDoHandle syncHandle;
-    OCDevAddr * _addr;
-    NSAccessPolicy accessPolicy;
 
-} NSProvider_internal;
+    bool isCloudConnection;
+    bool isSubscribing;
+
+    struct NSProviderConnectionInfo * next;
+
+} NSProviderConnectionInfo;
 
 typedef struct
 {
-    uint64_t messageId;
     char providerId[NS_DEVICE_ID_LENGTH];
-    NSSyncType state;
 
-    OCDevAddr * _addr;
-} NSSyncInfo_internal;
+    NSTopicLL * topicLL;
+
+    char * messageUri;
+    char * syncUri;
+    char * topicUri;
+
+    NSSelector accessPolicy;
+    NSProviderState state;
+
+    NSProviderConnectionInfo * connection;
+
+} NSProvider_internal;
 
 typedef struct
 {
-    // Mandatory
     uint64_t messageId;
     char providerId[NS_DEVICE_ID_LENGTH];
+    NSSyncType state;
 
-    //optional
-    NSMessageType type;
-    char * dateTime;
-    uint64_t ttl;
-    char * title;
-    char * contentText;
-    char * sourceName;
-    NSMediaContents mediaContents;
+    NSProviderConnectionInfo * connection;
 
-    OCDevAddr * _addr;
-    //NSConsumerMessageTypes messageTypes;
-    NSSyncType _messageTypes;
-} NSMessage_consumer;
+} NSSyncInfo_internal;
 
 bool NSIsStartedConsumer();
 void NSSetIsStartedConsumer(bool setValue);
 
-void NSSetDiscoverProviderCb(NSProviderDiscoveredCallback cb);
-void NSDiscoveredProvider(NSProvider * provider);
-
-void NSSetSubscriptionAcceptedCb(NSSubscriptionAcceptedCallback cb);
-void NSSubscriptionAccepted(NSProvider * provider);
+void NSSetProviderChangedCb(NSProviderStateCallback cb);
+void NSProviderChanged(NSProvider * provider, NSProviderState response);
 
 void NSSetMessagePostedCb(NSMessageReceivedCallback  cb);
 void NSMessagePost(NSMessage * obj);
@@ -187,22 +114,42 @@ void NSSetConsumerId(char * cId);
 char * NSMakeRequestUriWithConsumerId(const char * uri);
 
 NSTask * NSMakeTask(NSTaskType, void *);
-
 NSResult NSConsumerPushEvent(NSTask *);
 
-NSMessage_consumer * NSCopyMessage(NSMessage_consumer *);
-void NSRemoveMessage(NSMessage_consumer *);
+NSMessage * NSGetMessage(OCRepPayload * payload);
+NSMessage * NSCopyMessage(NSMessage *);
+void NSRemoveMessage(NSMessage *);
+
+void NSGetProviderPostClean(
+        char * pId, char * mUri, char * sUri, char * tUri, NSProviderConnectionInfo * connection);
+
+NSProvider_internal * NSGetProvider(OCClientResponse * clientResponse);
+NSProviderConnectionInfo * NSCreateProviderConnections(OCDevAddr *);
+NSProviderConnectionInfo * NSCopyProviderConnections(NSProviderConnectionInfo *);
+void NSRemoveConnections(NSProviderConnectionInfo *);
 
-NSProvider_internal * NSCopyProvider(NSProvider_internal *);
-void NSRemoveProvider(NSProvider_internal *);
+NSProvider_internal * NSCopyProvider_internal(NSProvider_internal *);
+NSProvider * NSCopyProvider(NSProvider_internal *);
+void NSRemoveProvider_internal(void *);
+void NSRemoveProvider(NSProvider *);
+
+NSTopicLL * NSCopyTopicNode(NSTopicLL *);
+void NSRemoveTopicNode(NSTopicLL *);
+NSResult NSInsertTopicNode(NSTopicLL *, NSTopicLL *);
+
+NSTopicLL * NSCopyTopicLL(NSTopicLL *);
+void NSRemoveTopicLL(NSTopicLL *);
 
 OCStackResult NSInvokeRequest(OCDoHandle * handle,
         OCMethod method, const OCDevAddr * addr,
         const char * queryUrl, OCPayload * payload,
-        void * callbackFunc, void * callbackData);
+        void * callbackFunc, void * callbackData,
+        OCClientContextDeleter cd, OCConnectivityType type);
+
+bool NSOCResultToSuccess(OCStackResult ret);
 
 #ifdef __cplusplus
 }
 #endif // __cplusplus
 
-#endif // _NS_CONSUMER_CONSTANTS_H_
+#endif // _NS_CONSUMER_COMMON_H_