replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / service / notification / src / consumer / NSConsumerCommon.h
index 4a09769..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" {
@@ -28,95 +28,128 @@ extern "C" {
 #include <stdio.h>
 #include <stdbool.h>
 
-#include "NSCommon.h"
+#include "NSConsumerInterface.h"
 #include "NSStructs.h"
 #include "ocstack.h"
 
-#define NS_LOG_PRINTF 0
-
-#define __NS_FILE__ ( strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__ )
-
-const char * NS_CONVERT_LEVEL(int level);
-
-// TODO fix ns log using oic log.
-#ifdef TB_LOG
-#include "logger.h"
-#define NS_CONSUMER_LOG_V(level, format, ...) (OIC_LOG_V((level), __NS_FILE__, (format), __VA_ARGS__))
-#define NS_CONSUMER_LOG(level, msg) (OIC_LOG((level), __NS_FILE__, (msg)))
-#else
-#include "logger.h"
-#define NS_CONSUMER_LOG_V(level, format, ...) { \
-        printf("%s: %s ", NS_CONVERT_LEVEL(level), __NS_FILE__); \
-        printf((format), __VA_ARGS__); \
-        printf("\n"); }
-#define NS_CONSUMER_LOG(level, msg) { \
-        printf("%s: %s ", NS_CONVERT_LEVEL(level), __NS_FILE__); \
-        printf((msg)); \
-        printf("\n"); }
-
-#endif
-
-#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
 
-typedef OCStackApplicationResult (*onRIResponseListener)(
-        void *, OCDoHandle, OCClientResponse *);
+typedef enum
+{
+    NS_DISCOVER_DEFAULT, // will work for adapter_ip.
+    NS_DISCOVER_UDP,
+    NS_DISCOVER_TCP,
+    NS_DISCOVER_CLOUD
+} NSConsumerDiscoverType;
 
 typedef enum
 {
-    Read,
-    Dismiss,
-    Notification,
-} NSConsumerMessageTypes;
+    NS_SELECTION_CONSUMER = 0,
+    NS_SELECTION_PROVIDER = 1
+} NSSelector;
+
+typedef struct NSProviderConnectionInfo
+{
+    OCDevAddr * addr;
+
+    OCDoHandle messageHandle;
+    OCDoHandle syncHandle;
+
+    bool isCloudConnection;
+    bool isSubscribing;
+
+    struct NSProviderConnectionInfo * next;
+
+} NSProviderConnectionInfo;
 
 typedef struct
 {
-    // Mandatory
-    char * mId;
-    char * mTitle;
+    char providerId[NS_DEVICE_ID_LENGTH];
 
-    //Optional
-    char * mContentText;
+    NSTopicLL * topicLL;
 
-    OCDevAddr * addr;
+    char * messageUri;
     char * syncUri;
-    NSConsumerMessageTypes type;
-} NSMessage_consumer;
+    char * topicUri;
+
+    NSSelector accessPolicy;
+    NSProviderState state;
+
+    NSProviderConnectionInfo * connection;
+
+} NSProvider_internal;
+
+typedef struct
+{
+    uint64_t messageId;
+    char providerId[NS_DEVICE_ID_LENGTH];
+    NSSyncType state;
+
+    NSProviderConnectionInfo * connection;
+
+} NSSyncInfo_internal;
 
 bool NSIsStartedConsumer();
 void NSSetIsStartedConsumer(bool setValue);
 
-void NSSetDiscoverProviderCb(NSProviderDiscoveredCallback cb);
-void NSDiscoveredProvider(NSProvider * handle);
+void NSSetProviderChangedCb(NSProviderStateCallback cb);
+void NSProviderChanged(NSProvider * provider, NSProviderState response);
 
-void NSSetNotificationPostedCb(NSNotificationReceivedCallback  cb);
-void NSNotificationPost(NSProvider * provider, NSMessage * obj);
+void NSSetMessagePostedCb(NSMessageReceivedCallback  cb);
+void NSMessagePost(NSMessage * obj);
 
-void NSSetNotificationSyncCb(NSSyncCallback cb);
-void NSNotificationSync(NSProvider * provider, NSSync * sync);
+void NSSetNotificationSyncCb(NSSyncInfoReceivedCallback cb);
+void NSNotificationSync(NSSyncInfo * sync);
 
-onRIResponseListener NSGetResponseListener();
-void NSSetResponseListener(onRIResponseListener cb);
+char ** NSGetConsumerId();
+void NSSetConsumerId(char * cId);
 
-NSTask * NSMakeTask(NSTaskType, void *);
+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_internal(NSProvider_internal *);
+NSProvider * NSCopyProvider(NSProvider_internal *);
+void NSRemoveProvider_internal(void *);
+void NSRemoveProvider(NSProvider *);
 
-OCStackResult NSRequestToResourceIntrospection(OCDoHandle * handle,
+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 * callback);
+        const char * queryUrl, OCPayload * payload,
+        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_