Init basesystem source codes.
[staging/basesystem.git] / nsframework / framework_unified / client / NS_FrameworkCore / src / frameworkunified_framework_error.cpp
1 /*
2  * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <native_service/frameworkunified_framework_error.hpp>
18 #include <cstdio>
19 #include <string>
20 #include "frameworkunified_framework_error_internal.hpp"
21
22 // using std::snprintf;
23 typedef std::string TErrorDesc;
24 typedef const TErrorDesc TCErrorDesc;
25
26 namespace {
27
28 PCSTR FrameworkunifiedStatusDesc(EFrameworkunifiedStatus status) {
29   switch (status) {
30     case eFrameworkunifiedStatusSessionLimitMaxedOut:
31       return "Session limit maxed out";
32     case eFrameworkunifiedStatusDbRecNotFound:
33       return "Db record not Found";
34     case eFrameworkunifiedStatusDbResultError:
35       return "Db result error";
36     case eFrameworkunifiedStatusDbExecuteFail:
37       return "Db execute failure";
38     case eFrameworkunifiedStatusSemCloseFail:
39       return "Semaphore close failure";
40     case eFrameworkunifiedStatusSemUnlockFail:
41       return "Semaphore unlock gailure";
42     case eFrameworkunifiedStatusSemLockFail:
43       return "Semaphore lock failure";
44     case eFrameworkunifiedStatusFail:
45       return "failure";
46     case eFrameworkunifiedStatusOK:
47       return "Status OK";
48     case eFrameworkunifiedStatusInvldBuf:
49       return "Invalid buffer";
50     case eFrameworkunifiedStatusInvldHandle:
51       return "Invalid handle";
52     case eFrameworkunifiedStatusInvldHndlType:
53       return "Invalid handle yype";
54     case eFrameworkunifiedStatusInvldQName:
55       return "Invalid queue name";
56     case eFrameworkunifiedStatusMsgQFull:
57       return "Message queue full";
58     case eFrameworkunifiedStatusInvldNotification:
59       return "Invliad notification";
60     case eFrameworkunifiedStatusInvldParam:
61       return "Invalid parameter";
62     case eFrameworkunifiedStatusInvldBufSize:
63       return "Invalid buffer size";
64     case eFrameworkunifiedStatusInvldID:
65       return "Invalid MemID";
66     case eFrameworkunifiedStatusCannotRelease:
67       return "Cannot release resource";
68     case eFrameworkunifiedStatusBadConnection:
69       return "Bad connection";
70     case eFrameworkunifiedStatusExit:
71       return "Exit";
72     case eFrameworkunifiedStatusNotImplemented:
73       return "Not implemented";
74     case eFrameworkunifiedStatusThreadBusy:
75       return "Thread busy";
76     case eFrameworkunifiedStatusThreadSelfJoin:
77       return "Attempted to self-join";
78     case eFrameworkunifiedStatusThreadInvalidVal:
79       return "Invalid value passed";
80     case eFrameworkunifiedStatusThreadNotExist:
81       return "Thread does not exist";
82     case eFrameworkunifiedStatusFault:
83       return "Fault";
84     case eFrameworkunifiedStatusServNotFound:
85       return "Service not found";
86     case eFrameworkunifiedStatusErrOther:
87     default:
88       return "Other error";
89   }
90 }
91
92 TCErrorDesc BuildFrameworkunifiedErrorDesc(EFrameworkunifiedStatus error, PCSTR errorMsg) {
93   CHAR buf[ MAX_QUEUE_MSG_SIZE ] = {};
94   snprintf(&buf[ 0 ],
95            MAX_QUEUE_MSG_SIZE,
96            "Framework Error: %s - %s",
97            FrameworkunifiedStatusDesc(error),
98            errorMsg != 0 ? errorMsg : NULL);
99   return TErrorDesc(&buf[ 0 ]);
100 }
101
102 TCErrorDesc BuildFrameworkunifiedSystemErrorDesc(EFrameworkunifiedSystemError error, PCSTR errorMsg) {
103   TErrorDesc l_cErrorMsg("Framework defined error desc: ");
104
105   switch (error) {
106     // Commented, because this is product specific error. Must handle by SystemServices only.
107     // case eFrameworkunifiedDSPHardwareReset : l_cErrorMsg.append("DSP HW RESET ERROR"); break;
108     default:
109       l_cErrorMsg.append("Other error");
110       break;
111   }
112
113   l_cErrorMsg.append(" :: Application provided error desc:");
114   l_cErrorMsg.append(errorMsg);
115   return l_cErrorMsg;
116 }
117
118 }  // end namespace
119
120
121
122 frameworkunified::framework::error::error::error(EFrameworkunifiedStatus error, PCSTR errorMsg)
123   : std::runtime_error(BuildFrameworkunifiedErrorDesc(error, errorMsg)),
124     m_error(error) {
125 }
126
127 frameworkunified::framework::error::CSystemError::CSystemError(EFrameworkunifiedSystemError error, PCSTR errorMsg)
128   : std::runtime_error(BuildFrameworkunifiedSystemErrorDesc(error, errorMsg)),
129     m_eSystemError(error) {
130 }