Imported Upstream version 0.9.2
[platform/upstream/iotivity.git] / resource / csdk / stack / samples / linux / SimpleClientServer / common.cpp
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 #include <stdio.h>
22 #include <stdlib.h>
23 #include <ocstack.h>
24
25 const char *getResult(OCStackResult result)
26 {
27     switch (result)
28     {
29         case OC_STACK_OK:
30             return "OC_STACK_OK";
31         case OC_STACK_RESOURCE_CREATED:
32             return "OC_STACK_RESOURCE_CREATED";
33         case OC_STACK_RESOURCE_DELETED:
34             return "OC_STACK_RESOURCE_DELETED";
35         case OC_STACK_INVALID_URI:
36             return "OC_STACK_INVALID_URI";
37         case OC_STACK_INVALID_QUERY:
38             return "OC_STACK_INVALID_QUERY";
39         case OC_STACK_INVALID_IP:
40             return "OC_STACK_INVALID_IP";
41         case OC_STACK_INVALID_PORT:
42             return "OC_STACK_INVALID_PORT";
43         case OC_STACK_INVALID_CALLBACK:
44             return "OC_STACK_INVALID_CALLBACK";
45         case OC_STACK_INVALID_METHOD:
46             return "OC_STACK_INVALID_METHOD";
47         case OC_STACK_NO_MEMORY:
48             return "OC_STACK_NO_MEMORY";
49         case OC_STACK_COMM_ERROR:
50             return "OC_STACK_COMM_ERROR";
51         case OC_STACK_INVALID_PARAM:
52             return "OC_STACK_INVALID_PARAM";
53         case OC_STACK_NOTIMPL:
54             return "OC_STACK_NOTIMPL";
55         case OC_STACK_NO_RESOURCE:
56             return "OC_STACK_NO_RESOURCE";
57         case OC_STACK_RESOURCE_ERROR:
58             return "OC_STACK_RESOURCE_ERROR";
59         case OC_STACK_SLOW_RESOURCE:
60             return "OC_STACK_SLOW_RESOURCE";
61         case OC_STACK_NO_OBSERVERS:
62             return "OC_STACK_NO_OBSERVERS";
63         case OC_STACK_UNAUTHORIZED_REQ:
64             return "OC_STACK_UNAUTHORIZED_REQ";
65 #ifdef WITH_PRESENCE
66         case OC_STACK_PRESENCE_STOPPED:
67             return "OC_STACK_PRESENCE_STOPPED";
68         case OC_STACK_PRESENCE_TIMEOUT:
69             return "OC_STACK_PRESENCE_TIMEOUT";
70 #endif
71         case OC_STACK_ERROR:
72             return "OC_STACK_ERROR";
73         default:
74             return "UNKNOWN";
75     }
76 }
77
78 void StripNewLineChar(char* str)
79 {
80     int i = 0;
81     if (str)
82     {
83         while( str[i])
84         {
85             if (str[i] == '\n')
86             {
87                 str[i] = '\0';
88             }
89             i++;
90         }
91     }
92 }
93