RDK Documentation (Open Sourced RDK Components)
ResponseStatus.cpp
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2016 RDK Management
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 
22 /**
23 * @defgroup trm
24 * @{
25 * @defgroup common
26 * @{
27 **/
28 
29 
30 #include <map>
31 #include <string>
32 
33 #include "trm/TRM.h"
34 #include "trm/ResponseStatus.h"
35 
36 
37 LOCAL_BEGIN_NAMESPACE
38 enum {
39  Ok,
40  GeneralError,
41  MalFormedRequest,
42  UnRecognizedRequest,
43 
44  InvalidToken,
45  InvalidState,
46  UserCancellation,
47  InsufficientResource,
48  MAX_ENUM_NUMBER
49 };
50 LOCAL_END_NAMESPACE
51 
52 TRM_BEGIN_NAMESPACE
53 
54 const Enum<ResponseStatus> ResponseStatus::kOk (Ok, "Ok");
55 const Enum<ResponseStatus> ResponseStatus::kGeneralError (GeneralError, "GeneralError");
56 const Enum<ResponseStatus> ResponseStatus::kMalFormedRequest (MalFormedRequest, "MalFormedRequest");
57 const Enum<ResponseStatus> ResponseStatus::kUnRecognizedRequest (UnRecognizedRequest, "UnRecognizedRequest");
58 
59 const Enum<ResponseStatus> ResponseStatus::kInvalidToken (MAKE_PAIR(InvalidToken));
60 const Enum<ResponseStatus> ResponseStatus::kInvalidState (MAKE_PAIR(InvalidState));
61 const Enum<ResponseStatus> ResponseStatus::kUserCancellation (MAKE_PAIR(UserCancellation));
62 const Enum<ResponseStatus> ResponseStatus::kInsufficientResource(MAKE_PAIR(InsufficientResource));
63 
64 const std::vector<const Enum<ResponseStatus> * > & ResponseStatus::getEnums(void)
65 {
66  static std::vector<const Enum<ResponseStatus> * > enums_;
67  if (enums_.size() == 0) {
68  enums_.push_back(&ResponseStatus::kOk);
69  enums_.push_back(&ResponseStatus::kGeneralError);
70  enums_.push_back(&ResponseStatus::kMalFormedRequest);
71  enums_.push_back(&ResponseStatus::kUnRecognizedRequest);
72  enums_.push_back(&ResponseStatus::kInvalidToken);
73  enums_.push_back(&ResponseStatus::kInvalidState);
74  enums_.push_back(&ResponseStatus::kUserCancellation);
75  enums_.push_back(&ResponseStatus::kInsufficientResource);
76 
77  Assert(enums_.size() == MAX_ENUM_NUMBER);
78  };
79 
80  return enums_;
81 }
82 
83 ResponseStatus::ResponseStatus(const Enum<ResponseStatus> &statusCode, const std::string &details)
84 : statusCode(statusCode), details(details)
85 {
86 }
87 
88 ResponseStatus::ResponseStatus(const char *name, const std::string &details)
89 : statusCode(Enum<ResponseStatus>::at(name)), details(details)
90 {
91 }
92 
93 ResponseStatus::~ResponseStatus(void)
94 {
95 }
96 
97 const Enum<ResponseStatus> & ResponseStatus::getStatusCode(void) const
98 {
99  return statusCode;
100 }
101 
102 
103 bool ResponseStatus::operator == (const ResponseStatus &that) const
104 {
105  return (this->statusCode == that.statusCode);
106 }
107 
108 ResponseStatus & ResponseStatus::operator += (const char *message)
109 {
110  details += message;
111  return *this;
112 }
113 ResponseStatus & ResponseStatus::operator= (const Enum<ResponseStatus> &status)
114 {
115  statusCode = status;
116  return *this;
117 }
118 
119 void ResponseStatus::print(void) const
120 {
121  statusCode.print();
122  std::cout << "[OBJ][" << klassName() << "][details]" << details << std::endl;
123 }
124 
125 const std::string & ResponseStatus::getDetails(void) const
126 {
127  return details;
128 }
129 
130 std::string & ResponseStatus::getDetails(void)
131 {
132  return details;
133 }
134 
135 
136 TRM_END_NAMESPACE
137 
138 
139 /** @} */
140 /** @} */