Merge branch 'master' into extended-easysetup
[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 #include <getopt.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_RESOURCE_CHANGED:
37             return "OC_STACK_RESOURCE_CHANGED";
38         case OC_STACK_INVALID_URI:
39             return "OC_STACK_INVALID_URI";
40         case OC_STACK_INVALID_QUERY:
41             return "OC_STACK_INVALID_QUERY";
42         case OC_STACK_INVALID_IP:
43             return "OC_STACK_INVALID_IP";
44         case OC_STACK_INVALID_PORT:
45             return "OC_STACK_INVALID_PORT";
46         case OC_STACK_INVALID_CALLBACK:
47             return "OC_STACK_INVALID_CALLBACK";
48         case OC_STACK_INVALID_METHOD:
49             return "OC_STACK_INVALID_METHOD";
50         case OC_STACK_NO_MEMORY:
51             return "OC_STACK_NO_MEMORY";
52         case OC_STACK_COMM_ERROR:
53             return "OC_STACK_COMM_ERROR";
54         case OC_STACK_INVALID_PARAM:
55             return "OC_STACK_INVALID_PARAM";
56         case OC_STACK_NOTIMPL:
57             return "OC_STACK_NOTIMPL";
58         case OC_STACK_NO_RESOURCE:
59             return "OC_STACK_NO_RESOURCE";
60         case OC_STACK_RESOURCE_ERROR:
61             return "OC_STACK_RESOURCE_ERROR";
62         case OC_STACK_SLOW_RESOURCE:
63             return "OC_STACK_SLOW_RESOURCE";
64         case OC_STACK_NO_OBSERVERS:
65             return "OC_STACK_NO_OBSERVERS";
66         case OC_STACK_UNAUTHORIZED_REQ:
67             return "OC_STACK_UNAUTHORIZED_REQ";
68 #ifdef WITH_PRESENCE
69         case OC_STACK_PRESENCE_STOPPED:
70             return "OC_STACK_PRESENCE_STOPPED";
71         case OC_STACK_PRESENCE_TIMEOUT:
72             return "OC_STACK_PRESENCE_TIMEOUT";
73 #endif
74         case OC_STACK_ERROR:
75             return "OC_STACK_ERROR";
76         default:
77             return "UNKNOWN";
78     }
79 }
80
81 void StripNewLineChar(char* str)
82 {
83     int i = 0;
84     if (str)
85     {
86         while( str[i])
87         {
88             if (str[i] == '\n')
89             {
90                 str[i] = '\0';
91             }
92             i++;
93         }
94     }
95 }
96