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