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"
32 #ifndef MAX_LENGTH_IPv4_ADDR
33 #define MAX_LENGTH_IPv4_ADDR 16
36 //-----------------------------------------------------------------------------
38 //-----------------------------------------------------------------------------
41 * List of methods that can be inititated from the client
44 TEST_DISCOVER_REQ = 1,
50 TEST_GET_UNAVAILABLE_RES_REQ_NON,
58 TEST_OBS_REQ_NON_CANCEL_IMM,
59 TEST_GET_REQ_NON_WITH_VENDOR_HEADER_OPTIONS,
67 //----------------------------------------------------------------------------
69 //----------------------------------------------------------------------------
71 /* call getResult in common.cpp to get the result in string format. */
72 const char *getResult(OCStackResult result);
74 /* Get the IP address of the server */
75 std::string getIPAddrTBServer(OCClientResponse * clientResponse);
77 /* Get the port number the server is listening on */
78 std::string getPortTBServer(OCClientResponse * clientResponse);
80 /* Returns the query string for GET and PUT operations */
81 std::string getQueryStrForGetPut(OCClientResponse * clientResponse);
83 /* Following are initialization functions for GET, Observe, PUT
84 * POST, Delete & Discovery operations
86 int InitGetRequestToUnavailableResource();
87 int InitObserveRequest(OCQualityOfService qos);
89 int InitGetRequest(OCQualityOfService qos, uint8_t withVendorSpecificHeaderOptions);
90 int InitPostRequest(OCQualityOfService qos);
91 int InitDeleteRequest(OCQualityOfService qos);
92 int InitGetRequest(OCQualityOfService qos);
95 /* Function to retrieve ip address, port no. of the server
96 * and query for the operations to be performed.
98 void parseClientResponse(OCClientResponse * clientResponse);
100 /* Call delete operation on already deleted resource */
101 void* RequestDeleteDeathResourceTask(void* myqos);
103 /* This method calls OCDoResource() which in turn makes calls
104 * to the lower layers
106 OCStackResult InvokeOCDoResource(std::ostringstream &query,
107 OCMethod method, OCQualityOfService qos,
108 OCClientResponseHandler cb, OCHeaderOption * options, uint8_t numOptions);
110 //-----------------------------------------------------------------------------
111 // Callback functions
112 //-----------------------------------------------------------------------------
114 /* Following are callback functions for the GET, Observe, PUT
115 * POST, Delete, Presence & Discovery operations
117 OCStackApplicationResult putReqCB(void* ctx, OCDoHandle handle, OCClientResponse * clientResponse);
119 OCStackApplicationResult postReqCB(void *ctx, OCDoHandle handle, OCClientResponse *clientResponse);
121 OCStackApplicationResult getReqCB(void* ctx, OCDoHandle handle, OCClientResponse * clientResponse);
123 OCStackApplicationResult obsReqCB(void* ctx, OCDoHandle handle, OCClientResponse * clientResponse);
125 OCStackApplicationResult presenceCB(void* ctx,
126 OCDoHandle handle, OCClientResponse * clientResponse);
128 OCStackApplicationResult deleteReqCB(void *ctx,
129 OCDoHandle handle, OCClientResponse *clientResponse);
131 OCStackApplicationResult discoveryReqCB(void* ctx, OCDoHandle handle,
132 OCClientResponse * clientResponse);