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,
49 //-----------------------------------------------------------------------------
51 //-----------------------------------------------------------------------------
58 OCConnectivityType connType;
62 //-----------------------------------------------------------------------------
64 //-----------------------------------------------------------------------------
66 /* call getResult in common.cpp to get the result in string format. */
67 const char *getResult(OCStackResult result);
69 /* Get the IP address of the server */
70 const char * getIPAddr(const OCClientResponse * clientResponse);
72 /* Get the port number the server is listening on */
73 const char * getPort(const OCClientResponse * clientResponse);
75 /* Performs GET/PUT/POST query on most recently discovered resource*/
78 /* Parses JSON payload received in the clientResponse to extract sid and resource uri information.
79 * Populates uri_c array with uris of the resources discovered and assigns sid_c with the server
80 * id received in the clientResponse.
82 int parseJSON(unsigned const char * resJSONPayload, char ** sid_c,
83 char *** uri_c, int * totalRes);
86 * Collect unique resource(sid:uri), regardless of the transport it arrives on.
88 void collectUniqueResource(const OCClientResponse * clientResponse);
91 * Insert the newly discovered unique resource(sid:uri) in the front of the resourceList
95 int insertResource(const char * sid, char const * uri,
96 const OCClientResponse * clientResponse);
99 * Returns most recently discovered resource
101 const ResourceNode * getResource();
104 * Frees the ResourceList
106 void freeResourceList();
108 /* Following are initialization functions for GET, PUT
109 * POST & Discovery operations
111 int InitPutRequest(OCQualityOfService qos);
112 int InitGetRequest(OCQualityOfService qos);
113 int InitPostRequest(OCQualityOfService qos);
116 /* Function to retrieve ip address, port no. of the server
117 * and query for the operations to be performed.
119 void parseClientResponse(OCClientResponse * clientResponse);
121 /* This method calls OCDoResource() which in turn makes calls
122 * to the lower layers
124 OCStackResult InvokeOCDoResource(std::ostringstream &query,
125 OCMethod method, OCQualityOfService qos,
126 OCClientResponseHandler cb, OCHeaderOption * options, uint8_t numOptions);
129 * SIGINT handler: set gQuitFlag to 1 for graceful termination
131 void handleSigInt(int signum);
134 * Printing helper functions
136 static void PrintUsage();
137 void printResourceList();
141 //-----------------------------------------------------------------------------
142 // Callback functions
143 //-----------------------------------------------------------------------------
145 /* Following are callback functions for the GET, PUT
146 * POST & Discovery operations
149 OCStackApplicationResult putReqCB(void* ctx, OCDoHandle handle, OCClientResponse * clientResponse);
151 OCStackApplicationResult postReqCB(void *ctx, OCDoHandle handle, OCClientResponse *clientResponse);
153 OCStackApplicationResult getReqCB(void* ctx, OCDoHandle handle, OCClientResponse * clientResponse);
155 OCStackApplicationResult discoveryReqCB(void* ctx, OCDoHandle handle,
156 OCClientResponse * clientResponse);
157 void StripNewLineChar(char* str);