Yingdi Yu | be4aeed | 2015-03-23 13:28:58 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | be998ac | 2017-05-06 13:11:42 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, Regents of the University of California |
Yingdi Yu | be4aeed | 2015-03-23 13:28:58 -0700 | [diff] [blame] | 4 | * |
Alexander Afanasyev | be998ac | 2017-05-06 13:11:42 -0700 | [diff] [blame] | 5 | * This file is part of NDN DeLorean, An Authentication System for Data Archives in |
| 6 | * Named Data Networking. See AUTHORS.md for complete list of NDN DeLorean authors |
| 7 | * and contributors. |
Yingdi Yu | be4aeed | 2015-03-23 13:28:58 -0700 | [diff] [blame] | 8 | * |
Alexander Afanasyev | be998ac | 2017-05-06 13:11:42 -0700 | [diff] [blame] | 9 | * NDN DeLorean is free software: you can redistribute it and/or modify it under |
| 10 | * the terms of the GNU General Public License as published by the Free Software |
| 11 | * Foundation, either version 3 of the License, or (at your option) any later |
| 12 | * version. |
Yingdi Yu | be4aeed | 2015-03-23 13:28:58 -0700 | [diff] [blame] | 13 | * |
Alexander Afanasyev | be998ac | 2017-05-06 13:11:42 -0700 | [diff] [blame] | 14 | * NDN DeLorean is distributed in the hope that it will be useful, but WITHOUT ANY |
| 15 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 16 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. |
Yingdi Yu | be4aeed | 2015-03-23 13:28:58 -0700 | [diff] [blame] | 17 | * |
Alexander Afanasyev | be998ac | 2017-05-06 13:11:42 -0700 | [diff] [blame] | 18 | * You should have received a copy of the GNU General Public License along with NDN |
| 19 | * DeLorean, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Yingdi Yu | be4aeed | 2015-03-23 13:28:58 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
Alexander Afanasyev | be998ac | 2017-05-06 13:11:42 -0700 | [diff] [blame] | 22 | #ifndef NDN_DELOREAN_CORE_LOGGER_RESPONSE_HPP |
| 23 | #define NDN_DELOREAN_CORE_LOGGER_RESPONSE_HPP |
Yingdi Yu | be4aeed | 2015-03-23 13:28:58 -0700 | [diff] [blame] | 24 | |
| 25 | #include "common.hpp" |
| 26 | #include "util/non-negative-integer.hpp" |
| 27 | #include <ndn-cxx/encoding/buffer.hpp> |
| 28 | |
Alexander Afanasyev | 49e2e4c | 2017-05-06 13:42:57 -0700 | [diff] [blame^] | 29 | namespace ndn { |
| 30 | namespace delorean { |
Yingdi Yu | be4aeed | 2015-03-23 13:28:58 -0700 | [diff] [blame] | 31 | |
| 32 | class LoggerResponse |
| 33 | { |
| 34 | public: |
| 35 | class Error : public std::runtime_error |
| 36 | { |
| 37 | public: |
| 38 | explicit |
| 39 | Error(const std::string& what) |
| 40 | : std::runtime_error(what) |
| 41 | { |
| 42 | } |
| 43 | }; |
| 44 | |
| 45 | public: |
| 46 | LoggerResponse(); |
| 47 | |
| 48 | LoggerResponse(int32_t resultCode, const std::string& resultMsg); |
| 49 | |
| 50 | LoggerResponse(const NonNegativeInteger& seqNo); |
| 51 | |
| 52 | int32_t |
| 53 | getCode() const |
| 54 | { |
| 55 | return m_code; |
| 56 | } |
| 57 | |
| 58 | const std::string& |
| 59 | getMsg() const |
| 60 | { |
| 61 | if (m_code == 0) |
| 62 | throw Error("Error msg is not available"); |
| 63 | |
| 64 | return m_msg; |
| 65 | } |
| 66 | |
| 67 | const NonNegativeInteger& |
| 68 | getDataSeqNo() const |
| 69 | { |
| 70 | if (m_code != 0) |
| 71 | throw Error("Data seqNo is not available"); |
| 72 | |
| 73 | return m_dataSeqNo; |
| 74 | } |
| 75 | |
| 76 | /// @brief Encode to a wire format or estimate wire format |
| 77 | template<ndn::encoding::Tag TAG> |
| 78 | size_t |
| 79 | wireEncode(ndn::EncodingImpl<TAG>& block) const; |
| 80 | |
| 81 | /// @brief Encode to a wire format |
| 82 | const Block& |
| 83 | wireEncode() const; |
| 84 | |
| 85 | /// @brief Decode from a wire format |
| 86 | void |
| 87 | wireDecode(const Block& wire); |
| 88 | |
| 89 | private: |
| 90 | int32_t m_code; |
| 91 | std::string m_msg; // optional |
| 92 | NonNegativeInteger m_dataSeqNo; // optional |
| 93 | |
| 94 | mutable Block m_wire; |
| 95 | }; |
| 96 | |
Alexander Afanasyev | 49e2e4c | 2017-05-06 13:42:57 -0700 | [diff] [blame^] | 97 | } // namespace delorean |
| 98 | } // namespace ndn |
Yingdi Yu | be4aeed | 2015-03-23 13:28:58 -0700 | [diff] [blame] | 99 | |
Alexander Afanasyev | be998ac | 2017-05-06 13:11:42 -0700 | [diff] [blame] | 100 | #endif // NDN_DELOREAN_CORE_LOGGER_RESPONSE_HPP |