/*****************************************************************************\
*                                                                             *
*  Name   : empty_service                                                     *
*  Author : Chris Koeritz                                                     *
*                                                                             *
*******************************************************************************
* Copyright (c) 2001-$now By Author.  This program is free software; you can  *
* redistribute it and/or modify it under the terms of the GNU General Public  *
* License as published by the Free Software Foundation; either version 2 of   *
* the License or (at your option) any later version.  This is online at:      *
*     http://www.fsf.org/copyleft/gpl.html                                    *
* Please send any updates to: fred@gruntose.com                               *
\*****************************************************************************/

#include "empty_service.h"

#include <basis/function.h>
#include <basis/istring.h>
#include <basis/portable.h>
#include <basis/string_array.h>
#include <loggers/console_logger.h>

const int SERVICE_SNOOZE_PERIOD = 20;
  // we sleep for this long between checks on our status.

console_logger out;

#define LOG(to_print) out.log(to_print)

empty_service::empty_service()
: service_root("null_service", "Null Service", string_array())
{
  FUNCDEF("constructor");
  LOG("beginning execution of null service...");
}

empty_service::~empty_service()
{
  FUNCDEF("destructor");
  LOG("null service exits.");
}

void empty_service::perform_service(int formal(argc), char **formal(argv))
{
  // report that we're starting up.
  if (!report_status(SERVICE_START_PENDING, NO_ERROR, 3000)) {
//what now?  write to a log file?
    return;
  }

  // report that we've begun normal execution.
  if (!report_status(SERVICE_RUNNING, NO_ERROR, 0)) {
//what now?  write to a log file?
    return;
  }

  while (true) {
    if (should_exit()) break;  // time to stop serving.

//maybe report running every second or so?
//would we want to set the wait hint at that point?

    portable::sleep_ms(SERVICE_SNOOZE_PERIOD);
  }

//report service exited, how?
  if (!report_status(SERVICE_RUNNING, NO_ERROR, 0)) {
//what now?  write to a log file?
    return;
  }
}

