anjana_sreekumar@infosys.com | 991c206 | 2020-01-08 11:42:57 +0530 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2019, Infosys Ltd. |
| 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 <debug.h> |
| 18 | |
| 19 | using namespace cmn::utils; |
| 20 | |
| 21 | Debug::Debug() |
| 22 | { |
| 23 | indent = 0; |
| 24 | newLine = true; |
| 25 | } |
| 26 | |
| 27 | Debug::~Debug() |
| 28 | { |
| 29 | //TODO |
| 30 | } |
| 31 | |
| 32 | void Debug::printDebugStream() |
| 33 | { |
| 34 | fprintf(stderr, "%s" , stream.str().c_str()); |
| 35 | } |
| 36 | |
| 37 | void Debug::clearStream() |
| 38 | { |
| 39 | stream.str(""); |
| 40 | } |
| 41 | |
| 42 | void Debug::printDebugStreamToFile() |
| 43 | { |
| 44 | // TODO |
| 45 | } |
| 46 | |
| 47 | void Debug::add(char* data) |
| 48 | { |
| 49 | if (newLine) |
| 50 | startNewLine(); |
| 51 | stream << data; |
| 52 | } |
| 53 | |
| 54 | void Debug::add(uint8_t data) |
| 55 | { |
| 56 | if (newLine) |
| 57 | startNewLine(); |
| 58 | stream << (uint16_t)data; |
| 59 | } |
| 60 | |
| 61 | void Debug::add(uint16_t data) |
| 62 | { |
| 63 | if (newLine) |
| 64 | startNewLine(); |
| 65 | stream << data; |
| 66 | } |
| 67 | |
| 68 | void Debug::add(uint32_t data) |
| 69 | { |
| 70 | if (newLine) |
| 71 | startNewLine(); |
| 72 | stream << data; |
| 73 | } |
| 74 | |
| 75 | void Debug::add(uint64_t data) |
| 76 | { |
| 77 | if (newLine) |
| 78 | startNewLine(); |
| 79 | stream << data; |
| 80 | } |
| 81 | |
| 82 | |
| 83 | void Debug::endOfLine() |
| 84 | { |
| 85 | stream <<"\n"; |
| 86 | newLine = true; |
| 87 | } |
| 88 | |
| 89 | void Debug::startNewLine() |
| 90 | { |
| 91 | uint8_t i; |
| 92 | for (i = 0; i<= indent; i++) |
| 93 | { |
| 94 | stream <<" "; |
| 95 | } |
| 96 | newLine = false; |
| 97 | } |
| 98 | |
| 99 | void Debug::incrIndent() |
| 100 | { |
| 101 | indent++; |
| 102 | } |
| 103 | |
| 104 | void Debug::decrIndent() |
| 105 | { |
| 106 | if (indent > 0) |
| 107 | indent --; |
| 108 | } |
| 109 | |
| 110 | void Debug::setHexOutput() |
| 111 | { |
| 112 | stream.setf(ios::hex, ios::basefield); |
| 113 | } |
| 114 | |
| 115 | void Debug::unsetHexOutput() |
| 116 | { |
| 117 | stream.unsetf(ios::hex); |
| 118 | } |
| 119 | |