iotivity 0.9.0
[platform/upstream/iotivity.git] / resource / csdk / stack / samples / linux / SimpleClientServer / occlientbasicops.h
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
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
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
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.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 #ifndef OCCLIENT_BASICOPS_H_
22 #define OCCLIENT_BASICOPS_H_
23
24 #include "ocstack.h"
25
26 //-----------------------------------------------------------------------------
27 // Defines
28 //-----------------------------------------------------------------------------
29 #define TAG "occlientbasicops"
30 #define DEFAULT_CONTEXT_VALUE 0x99
31 #ifndef MAX_LENGTH_IPv4_ADDR
32 #define MAX_LENGTH_IPv4_ADDR 16
33 #endif
34
35 //-----------------------------------------------------------------------------
36 // Typedefs
37 //-----------------------------------------------------------------------------
38
39 /**
40  * List of methods that can be inititated from the client
41  */
42 typedef enum {
43     TEST_DISCOVER_REQ = 1,
44     TEST_NON_CON_OP,
45     TEST_CON_OP,
46     MAX_TESTS
47 } CLIENT_TEST;
48
49 //-----------------------------------------------------------------------------
50 // Function prototype
51 //-----------------------------------------------------------------------------
52
53 /* call getResult in common.cpp to get the result in string format. */
54 const char *getResult(OCStackResult result);
55
56 /* Get the IP address of the server */
57 std::string getIPAddrTBServer(OCClientResponse * clientResponse);
58
59 /* Get the port number the server is listening on */
60 std::string getPortTBServer(OCClientResponse * clientResponse);
61
62 /* Returns the query string for GET and PUT operations */
63 std::string getQueryStrForGetPut(OCClientResponse * clientResponse);
64
65 /* Following are initialization functions for GET, PUT
66  * POST & Discovery operations
67  */
68 int InitPutRequest();
69 int InitGetRequest(OCQualityOfService qos);
70 int InitPostRequest(OCQualityOfService qos);
71 int InitDiscovery();
72
73 /* Function to retrieve ip address, port no. of the server
74  *  and query for the operations to be performed.
75  */
76 void parseClientResponse(OCClientResponse * clientResponse);
77
78 /* This method calls OCDoResource() which in turn makes calls
79  * to the lower layers
80  */
81 OCStackResult InvokeOCDoResource(std::ostringstream &query,
82         OCMethod method, OCQualityOfService qos,
83         OCClientResponseHandler cb, OCHeaderOption * options, uint8_t numOptions);
84
85 //-----------------------------------------------------------------------------
86 // Callback functions
87 //-----------------------------------------------------------------------------
88
89 /* Following are callback functions for the  GET, PUT
90  * POST & Discovery operations
91  */
92
93 OCStackApplicationResult putReqCB(void* ctx, OCDoHandle handle, OCClientResponse * clientResponse);
94
95 OCStackApplicationResult postReqCB(void *ctx, OCDoHandle handle, OCClientResponse *clientResponse);
96
97 OCStackApplicationResult getReqCB(void* ctx, OCDoHandle handle, OCClientResponse * clientResponse);
98
99 OCStackApplicationResult discoveryReqCB(void* ctx, OCDoHandle handle,
100         OCClientResponse * clientResponse);
101
102 #endif