iotivity 0.9.0
[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 inititated from the client
42  */
43 typedef enum {
44     TEST_DISCOVER_REQ = 1,
45     TEST_GET_REQ_NON,
46     TEST_PUT_REQ_NON,
47     TEST_POST_REQ_NON,
48     TEST_DELETE_REQ_NON,
49     TEST_OBS_REQ_NON,
50     TEST_GET_UNAVAILABLE_RES_REQ_NON,
51     TEST_GET_REQ_CON,
52     TEST_POST_REQ_CON,
53     TEST_DELETE_REQ_CON,
54     TEST_OBS_REQ_CON,
55 #ifdef WITH_PRESENCE
56     TEST_OBS_PRESENCE,
57     TEST_OBS_PRESENCE_WITH_FILTER,
58     TEST_OBS_PRESENCE_WITH_FILTERS,
59 #endif
60     TEST_OBS_REQ_NON_CANCEL_IMM,
61     TEST_GET_REQ_NON_WITH_VENDOR_HEADER_OPTIONS,
62     TEST_DISCOVER_DEV_REQ,
63     MAX_TESTS
64 } CLIENT_TEST;
65
66 #ifdef WITH_PRESENCE
67 int InitPresence();
68 #endif
69
70 //----------------------------------------------------------------------------
71 // Function prototype
72 //----------------------------------------------------------------------------
73
74 /* call getResult in common.cpp to get the result in string format. */
75 const char *getResult(OCStackResult result);
76
77 /* Get the IP address of the server */
78 std::string getIPAddrTBServer(OCClientResponse * clientResponse);
79
80 /* Get the port number the server is listening on */
81 std::string getPortTBServer(OCClientResponse * clientResponse);
82
83 /* Returns the query string for GET and PUT operations */
84 std::string getQueryStrForGetPut(OCClientResponse * clientResponse);
85
86 /* Following are initialization functions for GET, Observe, PUT
87  * POST, Delete & Discovery operations
88  */
89 int InitGetRequestToUnavailableResource();
90 int InitObserveRequest(OCQualityOfService qos);
91 int InitPutRequest();
92 int InitGetRequest(OCQualityOfService qos, uint8_t withVendorSpecificHeaderOptions);
93 int InitPostRequest(OCQualityOfService qos);
94 int InitDeleteRequest(OCQualityOfService qos);
95 int InitGetRequest(OCQualityOfService qos);
96 int InitDeviceDiscovery();
97 int InitDiscovery();
98
99 /* Function to retrieve ip address, port no. of the server
100  *  and query for the operations to be performed.
101  */
102 void parseClientResponse(OCClientResponse * clientResponse);
103
104 /* Call delete operation on already deleted resource */
105 void* RequestDeleteDeathResourceTask(void* myqos);
106
107 /* This method calls OCDoResource() which in turn makes calls
108  * to the lower layers
109  */
110 OCStackResult InvokeOCDoResource(std::ostringstream &query,
111         OCMethod method, OCQualityOfService qos,
112         OCClientResponseHandler cb, OCHeaderOption * options, uint8_t numOptions);
113
114 //-----------------------------------------------------------------------------
115 // Callback functions
116 //-----------------------------------------------------------------------------
117
118 /* Following are callback functions for the  GET, Observe, PUT
119  * POST, Delete, Presence & Discovery operations
120  */
121 OCStackApplicationResult putReqCB(void* ctx, OCDoHandle handle, OCClientResponse * clientResponse);
122
123 OCStackApplicationResult postReqCB(void *ctx, OCDoHandle handle, OCClientResponse *clientResponse);
124
125 OCStackApplicationResult getReqCB(void* ctx, OCDoHandle handle, OCClientResponse * clientResponse);
126
127 OCStackApplicationResult obsReqCB(void* ctx, OCDoHandle handle, OCClientResponse * clientResponse);
128
129 OCStackApplicationResult presenceCB(void* ctx,
130             OCDoHandle handle, OCClientResponse * clientResponse);
131
132 OCStackApplicationResult deleteReqCB(void *ctx,
133             OCDoHandle handle, OCClientResponse *clientResponse);
134
135 OCStackApplicationResult discoveryReqCB(void* ctx, OCDoHandle handle,
136         OCClientResponse * clientResponse);
137
138
139 #endif