Merge branch 'master' into simulator
[platform/upstream/iotivity.git] / resource / csdk / stack / samples / tizen / SimpleClientServer / common.cpp
1 //******************************************************************
2 //
3 // Copyright 2014 Samsung Electronics All Rights Reserved.
4 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
5 //
6 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 //
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 // you may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at
11 //
12 //      http://www.apache.org/licenses/LICENSE-2.0
13 //
14 // Unless required by applicable law or agreed to in writing, software
15 // distributed under the License is distributed on an "AS IS" BASIS,
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 // See the License for the specific language governing permissions and
18 // limitations under the License.
19 //
20 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <ocstack.h>
25
26 const char *getResult(OCStackResult result)
27 {
28     switch (result)
29     {
30         case OC_STACK_OK:
31             return "OC_STACK_OK";
32         case OC_STACK_RESOURCE_CREATED:
33             return "OC_STACK_RESOURCE_CREATED";
34         case OC_STACK_RESOURCE_DELETED:
35             return "OC_STACK_RESOURCE_DELETED";
36         case OC_STACK_INVALID_URI:
37             return "OC_STACK_INVALID_URI";
38         case OC_STACK_INVALID_QUERY:
39             return "OC_STACK_INVALID_QUERY";
40         case OC_STACK_INVALID_IP:
41             return "OC_STACK_INVALID_IP";
42         case OC_STACK_INVALID_PORT:
43             return "OC_STACK_INVALID_PORT";
44         case OC_STACK_INVALID_CALLBACK:
45             return "OC_STACK_INVALID_CALLBACK";
46         case OC_STACK_INVALID_METHOD:
47             return "OC_STACK_INVALID_METHOD";
48         case OC_STACK_NO_MEMORY:
49             return "OC_STACK_NO_MEMORY";
50         case OC_STACK_COMM_ERROR:
51             return "OC_STACK_COMM_ERROR";
52         case OC_STACK_INVALID_PARAM:
53             return "OC_STACK_INVALID_PARAM";
54         case OC_STACK_NOTIMPL:
55             return "OC_STACK_NOTIMPL";
56         case OC_STACK_NO_RESOURCE:
57             return "OC_STACK_NO_RESOURCE";
58         case OC_STACK_RESOURCE_ERROR:
59             return "OC_STACK_RESOURCE_ERROR";
60         case OC_STACK_SLOW_RESOURCE:
61             return "OC_STACK_SLOW_RESOURCE";
62         case OC_STACK_NO_OBSERVERS:
63             return "OC_STACK_NO_OBSERVERS";
64 #ifdef WITH_PRESENCE
65         case OC_STACK_PRESENCE_STOPPED:
66             return "OC_STACK_PRESENCE_STOPPED";
67         case OC_STACK_PRESENCE_TIMEOUT:
68             return "OC_STACK_PRESENCE_TIMEOUT";
69 #endif
70         case OC_STACK_ERROR:
71             return "OC_STACK_ERROR";
72         default:
73             return "UNKNOWN";
74     }
75 }
76
77 void StripNewLineChar(char* str)
78 {
79     int i = 0;
80     if (str)
81     {
82         while( str[i])
83         {
84             if (str[i] == '\n')
85             {
86                 str[i] = '\0';
87             }
88             i++;
89         }
90     }
91 }
92