Newer
Older
#ifndef SLD_HH
# define SLD_HH
# include <cassert>
# include <ios>
# include <iostream>
# include <fstream>
# include <sstream>
# include <map>
# include "error.hh"
typedef std::string string;
typedef std::stringstream sstream;
typedef std::ostream ostream;
typedef std::ifstream ifstream;
enum {
ERR_OK = 0,
ERR_USAGE = 1,
ERR_BADPARAM = 2,
ERR_FILE = 3,
ERR_NET = 4,
ERR_PROTO = 5,
ERR_AUTH = 6,
ERR_NOMEM = 41,
ERR_UNKNOWN = 42
};
// -----------------------------------------------------------------------------
// Gonstant
// -----------------------------------------------------------------------------
static const string VERSION = "1";
static const int MAX_LINE_SIZE = 512;
static const string RCV_DATA = "<< ";
static const string SND_DATA = ">> ";
// -----------------------------------------------------------------------------
// SLDAEMON CLASS
// -----------------------------------------------------------------------------
class SLDaemon
{
public:
static const string version;
string pass;
int verbose; //0=false, 1=true, 3=undef
string scriptdir;
string conffile;
};
int pid;
string name;
time_t start_time;
bool operator()(const Job &a, const Job &b);
};
inline bool verbose() const { return options_.verbose == 1; }
Options *getoptions(int argc, char *argv[]) const;
Options *getoptions(const string file) const;
void applyoptions(const Options *opt);
typedef std::set<Job, Job> t_job;
t_job jobs_;
void usage(const char *argv0) const;
void check_options() const;
void disconnect();
void send(const char *data, size_t len, bool buf = true);
void send(const string str, bool buf = true);
char *recvln();
void flush();
// protocol functions
void answer(const string &, bool = true);
void answer(long int, bool = true);
void warn(const string &, const string & = "");
void warn(long int, const string & = "");
void proto_violation();
// commmand functions
void cmd_version();
void cmd_list();
void cmd_reload();
void cmd_status();
void cmd_killall();
void cmd_kill(const char *line);
private:
static SLDaemon *instance_;
SLDaemon();
~SLDaemon() {}
SLDaemon(const SLDaemon &) { assert(true); }
SLDaemon &operator=(const SLDaemon &) { assert(true); return *instance_; }