1 //******************************************************************
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
11 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
27 //-----------------------------------------------------------------------------
29 //-----------------------------------------------------------------------------
30 #define TAG "occlient"
31 #define DEFAULT_CONTEXT_VALUE 0x99
32 #ifndef MAX_LENGTH_IPv4_ADDR
33 #define MAX_LENGTH_IPv4_ADDR 16
36 //-----------------------------------------------------------------------------
38 //-----------------------------------------------------------------------------
41 * List of methods that can be initiated from the client
44 TEST_DISCOVER_REQ = 1,
46 TEST_GET_REQ_NON_WITH_FILTERS,
51 TEST_GET_UNAVAILABLE_RES_REQ_NON,
58 TEST_OBS_PRESENCE_WITH_FILTER,
59 TEST_OBS_PRESENCE_WITH_FILTERS,
60 TEST_OBS_MULTICAST_PRESENCE,
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,
70 * List of connectivity types that can be initiated from the client
71 * Required for user input validation
74 CT_ADAPTER_DEFAULT = 0,
77 } CLIENT_CONNECTIVITY_TYPE;
83 //----------------------------------------------------------------------------
85 //----------------------------------------------------------------------------
86 std::string getConnectivityType (OCConnectivityType connType);
88 /* call getResult in common.cpp to get the result in string format. */
89 const char *getResult(OCStackResult result);
91 /* Get the IP address of the server */
92 std::string getIPAddrTBServer(OCClientResponse * clientResponse);
94 /* Get the port number the server is listening on */
95 std::string getPortTBServer(OCClientResponse * clientResponse);
97 /* Returns the query string for GET and PUT operations */
98 std::string getQueryStrForGetPut(OCClientResponse * clientResponse);
100 /* Following are initialization functions for GET, Observe, PUT
101 * POST, Delete & Discovery operations
103 int InitGetRequestToUnavailableResource(OCQualityOfService qos);
104 int InitObserveRequest(OCQualityOfService qos);
105 int InitPutRequest(OCQualityOfService qos);
106 int InitGetRequest(OCQualityOfService qos, uint8_t withVendorSpecificHeaderOptions, bool getWithQuery);
107 int InitPostRequest(OCQualityOfService qos);
108 int InitDeleteRequest(OCQualityOfService qos);
109 int InitGetRequest(OCQualityOfService qos);
110 int InitDeviceDiscovery(OCQualityOfService qos);
111 int InitPlatformDiscovery(OCQualityOfService qos);
112 int InitDiscovery(OCQualityOfService qos);
114 /* Function to retrieve ip address, port no. of the server
115 * and query for the operations to be performed.
117 void parseClientResponse(OCClientResponse * clientResponse);
119 /* Call delete operation on already deleted resource */
120 void* RequestDeleteDeathResourceTask(void* myqos);
122 /* This method calls OCDoResource() which in turn makes calls
123 * to the lower layers
125 OCStackResult InvokeOCDoResource(std::ostringstream &query,
126 OCMethod method, OCQualityOfService qos,
127 OCClientResponseHandler cb, OCHeaderOption * options, uint8_t numOptions);
129 //-----------------------------------------------------------------------------
130 // Callback functions
131 //-----------------------------------------------------------------------------
133 /* Following are callback functions for the GET, Observe, PUT
134 * POST, Delete, Presence & Discovery operations
136 OCStackApplicationResult putReqCB(void* ctx, OCDoHandle handle, OCClientResponse * clientResponse);
138 OCStackApplicationResult postReqCB(void *ctx, OCDoHandle handle, OCClientResponse *clientResponse);
140 OCStackApplicationResult getReqCB(void* ctx, OCDoHandle handle, OCClientResponse * clientResponse);
142 OCStackApplicationResult obsReqCB(void* ctx, OCDoHandle handle, OCClientResponse * clientResponse);
144 OCStackApplicationResult presenceCB(void* ctx,
145 OCDoHandle handle, OCClientResponse * clientResponse);
147 OCStackApplicationResult deleteReqCB(void *ctx,
148 OCDoHandle handle, OCClientResponse *clientResponse);
150 OCStackApplicationResult discoveryReqCB(void* ctx, OCDoHandle handle,
151 OCClientResponse * clientResponse);