// -*- C++ -*-
// This file is a part of the IncludeOS unikernel - www.includeos.org
//
// Copyright 2018 IncludeOS AS, Oslo, Norway
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include <os.hpp>
#include <vector>

class SystemLog
{
public:
  enum Flags {
    PANIC   = 0x1,
    REBOOT  = 0x2
  };

  // append @bytes to the system log
  static void write(const char*, size_t);

  // retrieve a copy of the memory-stored system log
  static std::vector<char> copy();

  // send whole system log to stdout @function
  static void print_to(os::print_func function);

  // set and get global bits
  static uint32_t get_flags();
  static void     set_flags(uint32_t flags);
  static void     clear_flags();

  // platform will initialize (create new or restore)
  static void initialize();
  static bool is_initialized();
};


inline void SystemLog::print_to(os::print_func funcptr)
{
  auto copy = SystemLog::copy();
  if (not copy.empty()) funcptr(copy.data(), copy.size());
}
