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