5776d32b60ddff16afa3642948f794974078e74e
[platform/core/api/audio-io.git] / src / cpp / CAudioError.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
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 <stdio.h>
18 #include <string.h>
19 #include <dlog.h>
20 #include "CAudioIODef.h"
21
22 using namespace std;
23 using namespace tizen_media_audio;
24
25 /**
26  * class CAudioError
27  */
28 CAudioError::CAudioError(EError err, const char* msg, const char* file, const char* func, int line) :
29     __mError(err),
30     __mMsg(msg) {
31     char __mErrorMsg[MSG_LENGTH] = { 0, };
32     snprintf(__mErrorMsg, MSG_LENGTH, "[%s|%s|%s(%d)|"
33               COLOR_CYAN   "%s"     COLOR_END "]",
34              __convertErrorToString(__mError), file, func, line, msg);
35
36     __mFullMsg = __mErrorMsg;
37 }
38
39 const char* CAudioError::getErrorMsg() const noexcept {
40     return what();
41 }
42
43 const CAudioError::EError CAudioError::getError() const noexcept {
44     return __mError;
45 }
46
47 const char* CAudioError::__convertErrorToString(EError err) noexcept {
48     switch (err) {
49     default:
50     case EError::ERROR_NONE:                return COLOR_GREEN "ERROR_NONE"               COLOR_END;
51     case EError::ERROR_INVALID_ARGUMENT:    return COLOR_RED   "ERROR_INVALID_ARGUMENT"   COLOR_END;
52 //LCOV_EXCL_START
53     case EError::ERROR_INVALID_HANDLE:      return COLOR_RED   "ERROR_INVALID_HANDLE"     COLOR_END;
54     case EError::ERROR_INVALID_POINTER:     return COLOR_RED   "ERROR_INVALID_POINTER"    COLOR_END;
55 //LCOV_EXCL_STOP
56     case EError::ERROR_INVALID_OPERATION:   return COLOR_RED   "ERROR_INVALID_OPERATION"  COLOR_END;
57     case EError::ERROR_INVALID_STATE:       return COLOR_RED   "ERROR_INVALID_STATE"      COLOR_END;
58     case EError::ERROR_NOT_INITIALIZED:     return COLOR_RED   "ERROR_NOT_INITIALIZED"    COLOR_END;
59     case EError::ERROR_NOT_SUPPORTED:       return COLOR_RED   "ERROR_NOT_SUPPORTED"      COLOR_END;
60     case EError::ERROR_NOT_SUPPORTED_TYPE:  return COLOR_RED   "ERROR_NOT_SUPPORTED_TYPE" COLOR_END;
61 //LCOV_EXCL_START
62     case EError::ERROR_PERMISSION_DENIED:   return COLOR_RED   "ERROR_PERMISSION_DENIED"  COLOR_END;
63     case EError::ERROR_DEVICE_POLICY_RESTRICTION:   return COLOR_RED   "ERROR_DEVICE_POLICY_RESTRICTION"  COLOR_END;
64     case EError::ERROR_DEVICE_NOT_OPENED:   return COLOR_RED   "ERROR_DEVICE_NOT_OPENED"  COLOR_END;
65     case EError::ERROR_DEVICE_NOT_CLOSED:   return COLOR_RED   "ERROR_DEVICE_NOT_CLOSED"  COLOR_END;
66     case EError::ERROR_OUT_OF_MEMORY:       return COLOR_RED   "ERROR_OUT_OF_MEMORY"      COLOR_END;
67     case EError::ERROR_INTERNAL_OPERATION:  return COLOR_RED   "ERROR_INTERNAL_OPERATION" COLOR_END;
68     case EError::ERROR_FAILED_OPERATION:    return COLOR_RED   "ERROR_FAILED_OPERATION"   COLOR_END;
69     case EError::ERROR_POLICY_BLOCKED:      return COLOR_RED   "ERROR_POLICY_BLOCKED"     COLOR_END;
70     case EError::ERROR_POLICY_INTERRUPTED:  return COLOR_RED   "ERROR_POLICY_INTERRUPTED" COLOR_END;
71     case EError::ERROR_POLICY_DUPLICATED:   return COLOR_RED   "ERROR_POLICY_DUPLICATED"  COLOR_END;
72 //LCOV_EXCL_STOP
73     }
74 }