Imported Upstream version 0.9.1
[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 #ifdef WITH_PRESENCE
64         case OC_STACK_PRESENCE_STOPPED:
65             return "OC_STACK_PRESENCE_STOPPED";
66         case OC_STACK_PRESENCE_TIMEOUT:
67             return "OC_STACK_PRESENCE_TIMEOUT";
68 #endif
69         case OC_STACK_ERROR:
70             return "OC_STACK_ERROR";
71         default:
72             return "UNKNOWN";
73     }
74 }
75
76 void StripNewLineChar(char* str)
77 {
78     int i = 0;
79     if (str)
80     {
81         while( str[i])
82         {
83             if (str[i] == '\n')
84             {
85                 str[i] = '\0';
86             }
87             i++;
88         }
89     }
90 }
91