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
32 //-----------------------------------------------------------------------------
34 //-----------------------------------------------------------------------------
37 * List of methods that can be inititated from the client
40 TEST_DISCOVER_REQ = 1,
47 * List of connectivity types that can be initiated from the client
48 * Required for user input validation
51 CT_ADAPTER_DEFAULT = 0,
54 } CLIENT_CONNECTIVITY_TYPE;
56 //-----------------------------------------------------------------------------
58 //-----------------------------------------------------------------------------
67 //-----------------------------------------------------------------------------
69 //-----------------------------------------------------------------------------
71 /* call getResult in common.cpp to get the result in string format. */
72 const char *getResult(OCStackResult result);
74 /* Performs GET/PUT/POST query on most recently discovered resource*/
77 /* Parses JSON payload received in the clientResponse to extract sid and resource uri information.
78 * Populates uri_c array with uris of the resources discovered and assigns sid_c with the server
79 * id received in the clientResponse.
81 int parseJSON(unsigned const char * resJSONPayload, char ** sid_c,
82 char *** uri_c, int * totalRes);
85 * Collect unique resource(sid:uri), regardless of the transport it arrives on.
87 void collectUniqueResource(const OCClientResponse * clientResponse);
90 * Insert the newly discovered unique resource(sid:uri) in the front of the resourceList
94 int insertResource(const char * sid, char const * uri,
95 const OCClientResponse * clientResponse);
98 * Returns most recently discovered resource
100 const ResourceNode * getResource();
103 * Frees the ResourceList
105 void freeResourceList();
107 /* Following are initialization functions for GET, PUT
108 * POST & Discovery operations
110 int InitPutRequest(OCQualityOfService qos);
111 int InitGetRequest(OCQualityOfService qos);
112 int InitPostRequest(OCQualityOfService qos);
115 /* Function to retrieve ip address, port no. of the server
116 * and query for the operations to be performed.
118 void parseClientResponse(OCClientResponse * clientResponse);
120 /* This method calls OCDoResource() which in turn makes calls
121 * to the lower layers
123 OCStackResult InvokeOCDoResource(std::ostringstream &query,
124 OCMethod method, OCDevAddr *dest, OCQualityOfService qos,
125 OCClientResponseHandler cb, OCHeaderOption * options, uint8_t numOptions);
128 * SIGINT handler: set gQuitFlag to 1 for graceful termination
130 void handleSigInt(int signum);
133 * Printing helper functions
135 static void PrintUsage();
136 void printResourceList();
140 //-----------------------------------------------------------------------------
141 // Callback functions
142 //-----------------------------------------------------------------------------
144 /* Following are callback functions for the GET, PUT
145 * POST & Discovery operations
148 OCStackApplicationResult putReqCB(void* ctx, OCDoHandle handle, OCClientResponse * clientResponse);
150 OCStackApplicationResult postReqCB(void *ctx, OCDoHandle handle, OCClientResponse *clientResponse);
152 OCStackApplicationResult getReqCB(void* ctx, OCDoHandle handle, OCClientResponse * clientResponse);
154 OCStackApplicationResult discoveryReqCB(void* ctx, OCDoHandle handle,
155 OCClientResponse * clientResponse);
156 void StripNewLineChar(char* str);