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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #ifndef OCCLIENT_BASICOPS_H_
22 #define OCCLIENT_BASICOPS_H_
26 //-----------------------------------------------------------------------------
28 //-----------------------------------------------------------------------------
29 #define TAG "occlientbasicops"
30 #define DEFAULT_CONTEXT_VALUE 0x99
31 #ifndef MAX_LENGTH_IPv4_ADDR
32 #define MAX_LENGTH_IPv4_ADDR 16
35 //-----------------------------------------------------------------------------
37 //-----------------------------------------------------------------------------
40 * List of methods that can be inititated from the client
43 TEST_DISCOVER_REQ = 1,
50 * List of connectivity types that can be initiated from the client
51 * Required for user input validation
54 CT_ADAPTER_DEFAULT = 0,
57 } CLIENT_CONNECTIVITY_TYPE;
59 //-----------------------------------------------------------------------------
61 //-----------------------------------------------------------------------------
68 OCConnectivityType connType;
72 //-----------------------------------------------------------------------------
74 //-----------------------------------------------------------------------------
76 /* call getResult in common.cpp to get the result in string format. */
77 const char *getResult(OCStackResult result);
79 /* Get the IP address of the server */
80 const char * getIPAddr(const OCClientResponse * clientResponse);
82 /* Get the port number the server is listening on */
83 const char * getPort(const OCClientResponse * clientResponse);
85 /* Performs GET/PUT/POST query on most recently discovered resource*/
88 /* Parses JSON payload received in the clientResponse to extract sid and resource uri information.
89 * Populates uri_c array with uris of the resources discovered and assigns sid_c with the server
90 * id received in the clientResponse.
92 int parseJSON(unsigned const char * resJSONPayload, char ** sid_c,
93 char *** uri_c, int * totalRes);
96 * Collect unique resource(sid:uri), regardless of the transport it arrives on.
98 void collectUniqueResource(const OCClientResponse * clientResponse);
101 * Insert the newly discovered unique resource(sid:uri) in the front of the resourceList
105 int insertResource(const char * sid, char const * uri,
106 const OCClientResponse * clientResponse);
109 * Returns most recently discovered resource
111 const ResourceNode * getResource();
114 * Frees the ResourceList
116 void freeResourceList();
118 /* Following are initialization functions for GET, PUT
119 * POST & Discovery operations
121 int InitPutRequest(OCQualityOfService qos);
122 int InitGetRequest(OCQualityOfService qos);
123 int InitPostRequest(OCQualityOfService qos);
126 /* Function to retrieve ip address, port no. of the server
127 * and query for the operations to be performed.
129 void parseClientResponse(OCClientResponse * clientResponse);
131 /* This method calls OCDoResource() which in turn makes calls
132 * to the lower layers
134 OCStackResult InvokeOCDoResource(std::ostringstream &query,
135 OCMethod method, OCQualityOfService qos,
136 OCClientResponseHandler cb, OCHeaderOption * options, uint8_t numOptions);
139 * SIGINT handler: set gQuitFlag to 1 for graceful termination
141 void handleSigInt(int signum);
144 * Printing helper functions
146 static void PrintUsage();
147 void printResourceList();
151 //-----------------------------------------------------------------------------
152 // Callback functions
153 //-----------------------------------------------------------------------------
155 /* Following are callback functions for the GET, PUT
156 * POST & Discovery operations
159 OCStackApplicationResult putReqCB(void* ctx, OCDoHandle handle, OCClientResponse * clientResponse);
161 OCStackApplicationResult postReqCB(void *ctx, OCDoHandle handle, OCClientResponse *clientResponse);
163 OCStackApplicationResult getReqCB(void* ctx, OCDoHandle handle, OCClientResponse * clientResponse);
165 OCStackApplicationResult discoveryReqCB(void* ctx, OCDoHandle handle,
166 OCClientResponse * clientResponse);
167 void StripNewLineChar(char* str);