empty_service.cpp

Go to the documentation of this file.
00001 /*****************************************************************************\
00002 *                                                                             *
00003 *  Name   : empty_service                                                     *
00004 *  Author : Chris Koeritz                                                     *
00005 *                                                                             *
00006 *******************************************************************************
00007 * Copyright (c) 2001-$now By Author.  This program is free software; you can  *
00008 * redistribute it and/or modify it under the terms of the GNU General Public  *
00009 * License as published by the Free Software Foundation; either version 2 of   *
00010 * the License or (at your option) any later version.  This is online at:      *
00011 *     http://www.fsf.org/copyleft/gpl.html                                    *
00012 * Please send any updates to: fred@gruntose.com                               *
00013 \*****************************************************************************/
00014 
00015 #include "empty_service.h"
00016 
00017 #include <basis/function.h>
00018 #include <basis/istring.h>
00019 #include <basis/portable.h>
00020 #include <basis/string_array.h>
00021 #include <loggers/console_logger.h>
00022 
00023 const int SERVICE_SNOOZE_PERIOD = 20;
00024   // we sleep for this long between checks on our status.
00025 
00026 console_logger out;
00027 
00028 #define LOG(to_print) out.log(to_print)
00029 
00030 empty_service::empty_service()
00031 : service_root("null_service", "Null Service", string_array())
00032 {
00033   FUNCDEF("constructor");
00034   LOG("beginning execution of null service...");
00035 }
00036 
00037 empty_service::~empty_service()
00038 {
00039   FUNCDEF("destructor");
00040   LOG("null service exits.");
00041 }
00042 
00043 void empty_service::perform_service(int formal(argc), char **formal(argv))
00044 {
00045   // report that we're starting up.
00046   if (!report_status(SERVICE_START_PENDING, NO_ERROR, 3000)) {
00047 //what now?  write to a log file?
00048     return;
00049   }
00050 
00051   // report that we've begun normal execution.
00052   if (!report_status(SERVICE_RUNNING, NO_ERROR, 0)) {
00053 //what now?  write to a log file?
00054     return;
00055   }
00056 
00057   while (true) {
00058     if (should_exit()) break;  // time to stop serving.
00059 
00060 //maybe report running every second or so?
00061 //would we want to set the wait hint at that point?
00062 
00063     portable::sleep_ms(SERVICE_SNOOZE_PERIOD);
00064   }
00065 
00066 //report service exited, how?
00067   if (!report_status(SERVICE_RUNNING, NO_ERROR, 0)) {
00068 //what now?  write to a log file?
00069     return;
00070   }
00071 }
00072 

Generated on Fri Nov 28 04:28:51 2008 for HOOPLE Libraries by  doxygen 1.5.1