replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / resource / csdk / stack / samples / tizen / SimpleClientServer / occlient.h
1 //******************************************************************
2 //
3 // Copyright 2014 Samsung Electronics All Rights Reserved.
4 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
5 //
6 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 //
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 // you may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at
11 //
12 //      http://www.apache.org/licenses/LICENSE-2.0
13 //
14 // Unless required by applicable law or agreed to in writing, software
15 // distributed under the License is distributed on an "AS IS" BASIS,
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 // See the License for the specific language governing permissions and
18 // limitations under the License.
19 //
20 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21
22 #ifndef OCCLIENT_H_
23 #define OCCLIENT_H_
24
25 #include "ocstack.h"
26
27
28 //-----------------------------------------------------------------------------
29 // Defines
30 //-----------------------------------------------------------------------------
31 #define TAG "occlient"
32 #define DEFAULT_CONTEXT_VALUE 0x99
33 #ifndef MAX_LENGTH_IPv4_ADDR
34 #define MAX_LENGTH_IPv4_ADDR 16
35 #endif
36
37 //-----------------------------------------------------------------------------
38 // Typedefs
39 //-----------------------------------------------------------------------------
40
41 /**
42  * List of methods that can be initiated from the client
43  */
44 typedef enum {
45     TEST_DISCOVER_REQ = 1,
46     TEST_GET_REQ_NON,
47     TEST_GET_REQ_NON_WITH_FILTERS,
48     TEST_PUT_REQ_NON,
49     TEST_POST_REQ_NON,
50     TEST_DELETE_REQ_NON,
51     TEST_OBS_REQ_NON,
52     TEST_GET_UNAVAILABLE_RES_REQ_NON,
53     TEST_GET_REQ_CON,
54     TEST_POST_REQ_CON,
55     TEST_DELETE_REQ_CON,
56     TEST_OBS_REQ_CON,
57 #ifdef WITH_PRESENCE
58     TEST_OBS_PRESENCE,
59     TEST_OBS_PRESENCE_WITH_FILTER,
60     TEST_OBS_PRESENCE_WITH_FILTERS,
61     TEST_OBS_MULTICAST_PRESENCE,
62 #endif
63     TEST_OBS_REQ_NON_CANCEL_IMM,
64     TEST_GET_REQ_NON_WITH_VENDOR_HEADER_OPTIONS,
65     TEST_DISCOVER_PLATFORM_REQ,
66     TEST_DISCOVER_DEV_REQ,
67     MAX_TESTS
68 } CLIENT_TEST;
69
70 /**
71  * List of connectivity types that can be initiated from the client
72  * Required for user input validation
73  */
74 typedef enum {
75     CT_ADAPTER_DEFAULT = 0,
76     CT_IP,
77     CT_EDR,
78     CT_TCP,
79     MAX_CT
80 } CLIENT_CONNECTIVITY_TYPE;
81
82 #ifdef WITH_PRESENCE
83 int InitPresence();
84 #endif
85
86 //----------------------------------------------------------------------------
87 // Function prototype
88 //----------------------------------------------------------------------------
89 std::string getConnectivityType (OCConnectivityType connType);
90
91 /* call getResult in common.cpp to get the result in string format. */
92 const char *getResult(OCStackResult result);
93
94 /* Get the IP address of the server */
95 std::string getIPAddrTBServer(OCClientResponse * clientResponse);
96
97 /* Get the port number the server is listening on */
98 std::string getPortTBServer(OCClientResponse * clientResponse);
99
100 /* Returns the query string for GET and PUT operations */
101 std::string getQueryStrForGetPut(OCClientResponse * clientResponse);
102
103 /* Following are initialization functions for GET, Observe, PUT
104  * POST, Delete & Discovery operations
105  */
106 int InitGetRequestToUnavailableResource(OCQualityOfService qos);
107 int InitObserveRequest(OCQualityOfService qos);
108 int InitPutRequest(OCQualityOfService qos);
109 int InitGetRequest(OCQualityOfService qos, uint8_t withVendorSpecificHeaderOptions, bool getWithQuery);
110 int InitPostRequest(OCQualityOfService qos);
111 int InitDeleteRequest(OCQualityOfService qos);
112 int InitGetRequest(OCQualityOfService qos);
113 int InitDeviceDiscovery(OCQualityOfService qos);
114 int InitPlatformDiscovery(OCQualityOfService qos);
115 int InitDiscovery(OCQualityOfService qos);
116
117 /* Function to retrieve ip address, port no. of the server
118  *  and query for the operations to be performed.
119  */
120 void parseClientResponse(OCClientResponse * clientResponse);
121
122 /* Call delete operation on already deleted resource */
123 void* RequestDeleteDeathResourceTask(void* myqos);
124
125 /* This method calls OCDoResource() which in turn makes calls
126  * to the lower layers
127  */
128 OCStackResult InvokeOCDoResource(std::ostringstream &query,
129         OCMethod method, OCQualityOfService qos,
130         OCClientResponseHandler cb, OCHeaderOption * options, uint8_t numOptions);
131
132 //-----------------------------------------------------------------------------
133 // Callback functions
134 //-----------------------------------------------------------------------------
135
136 /* Following are callback functions for the  GET, Observe, PUT
137  * POST, Delete, Presence & Discovery operations
138  */
139 OCStackApplicationResult putReqCB(void* ctx, OCDoHandle handle, OCClientResponse * clientResponse);
140
141 OCStackApplicationResult postReqCB(void *ctx, OCDoHandle handle, OCClientResponse *clientResponse);
142
143 OCStackApplicationResult getReqCB(void* ctx, OCDoHandle handle, OCClientResponse * clientResponse);
144
145 OCStackApplicationResult obsReqCB(void* ctx, OCDoHandle handle, OCClientResponse * clientResponse);
146
147 OCStackApplicationResult presenceCB(void* ctx,
148             OCDoHandle handle, OCClientResponse * clientResponse);
149
150 OCStackApplicationResult deleteReqCB(void *ctx,
151             OCDoHandle handle, OCClientResponse *clientResponse);
152
153 OCStackApplicationResult discoveryReqCB(void* ctx, OCDoHandle handle,
154         OCClientResponse * clientResponse);
155
156
157 #endif
158