3c91393b0e2f40a5dcd90b549f9ba98e1cba1796
[platform/upstream/iotivity.git] / resource / csdk / stack / samples / linux / SimpleClientServer / occlientslow.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 "occlientslow"
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 {
44     TEST_DISCOVER_REQ = 1,
45     TEST_NON_CON_OP,
46     TEST_CON_OP,
47     MAX_TESTS
48 } CLIENT_TEST;
49
50 /**
51  * List of connectivity types that can be initiated from the client
52  * Required for user input validation
53  */
54 typedef enum {
55     CT_ADAPTER_DEFAULT = 0,
56     CT_IP,
57     MAX_CT
58 } CLIENT_CONNECTIVITY_TYPE;
59
60 //-----------------------------------------------------------------------------
61 // Function prototype
62 //-----------------------------------------------------------------------------
63
64 /* call getResult in common.cpp to get the result in string format. */
65 const char *getResult(OCStackResult result);
66
67 /* Get the IP address of the server */
68 std::string getIPAddrTBServer(OCClientResponse * clientResponse);
69
70 /* Get the port number the server is listening on */
71 std::string getPortTBServer(OCClientResponse * clientResponse);
72
73 /* Returns the query string for GET and PUT operations */
74 std::string getQueryStrForGetPut(OCClientResponse * clientResponse);
75
76 /* Following are initialization functions for GET, PUT
77  * POST & Discovery operations
78  */
79 int InitGetRequest(OCQualityOfService qos);
80 int InitDiscovery();
81
82 /* Function to retrieve ip address, port no. of the server
83  *  and query for the operations to be performed.
84  */
85 void parseClientResponse(OCClientResponse * clientResponse);
86
87 /* This function calls OCDoResource() which in turn makes calls
88  * to the lower layers
89  */
90 OCStackResult InvokeOCDoResource(std::ostringstream &query,
91         OCMethod method, OCQualityOfService qos,
92         OCClientResponseHandler cb, OCHeaderOption * options, uint8_t numOptions);
93
94 //-----------------------------------------------------------------------------
95 // Callback functions
96 //-----------------------------------------------------------------------------
97
98 /* Following are callback functions for the  GET and Discovery operations
99  */
100
101 OCStackApplicationResult getReqCB(void* ctx, OCDoHandle handle, OCClientResponse * clientResponse);
102
103 OCStackApplicationResult discoveryReqCB(void* ctx, OCDoHandle handle,
104         OCClientResponse * clientResponse);
105
106 #endif
107