blob: 2ba549161805df3ac89f35a1820fa07c02cdac2f [file] [log] [blame]
Yingdi Yube4aeed2015-03-23 13:28:58 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -07003 * Copyright (c) 2014-2017, Regents of the University of California
Yingdi Yube4aeed2015-03-23 13:28:58 -07004 *
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -07005 * 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 Yube4aeed2015-03-23 13:28:58 -07008 *
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -07009 * 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 Yube4aeed2015-03-23 13:28:58 -070013 *
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -070014 * 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 Yube4aeed2015-03-23 13:28:58 -070017 *
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -070018 * 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 Yube4aeed2015-03-23 13:28:58 -070020 */
21
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -070022#ifndef NDN_DELOREAN_CORE_LOGGER_RESPONSE_HPP
23#define NDN_DELOREAN_CORE_LOGGER_RESPONSE_HPP
Yingdi Yube4aeed2015-03-23 13:28:58 -070024
25#include "common.hpp"
26#include "util/non-negative-integer.hpp"
27#include <ndn-cxx/encoding/buffer.hpp>
28
Alexander Afanasyev49e2e4c2017-05-06 13:42:57 -070029namespace ndn {
30namespace delorean {
Yingdi Yube4aeed2015-03-23 13:28:58 -070031
32class LoggerResponse
33{
34public:
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
45public:
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
89private:
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 Afanasyev49e2e4c2017-05-06 13:42:57 -070097} // namespace delorean
98} // namespace ndn
Yingdi Yube4aeed2015-03-23 13:28:58 -070099
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -0700100#endif // NDN_DELOREAN_CORE_LOGGER_RESPONSE_HPP