Skip to content
daemon.hh 2.64 KiB
Newer Older
Seblu's avatar
Seblu committed
/*
  This file is part of SLD.
  Copyright (C) 2008 Sebastien LUTTRINGER <contact@seblu.net>

  SLD is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
Seblu's avatar
Seblu committed
  the Free Software Foundation; version 2 of the License.
Seblu's avatar
Seblu committed

  SLD is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with SLD; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#ifndef DAEMON_HH
# define DAEMON_HH
Seblu's avatar
Seblu committed

# include "sld.hh"
# include "sll/connection.hh"
Seblu's avatar
Seblu committed
# include "options.hh"

Seblu's avatar
Seblu committed

// -----------------------------------------------------------------------------
// SLDAEMON CLASS
// -----------------------------------------------------------------------------

class SLDaemon
{
public:

  static const string version;
  static SLDaemon &Instance();
Seblu's avatar
Seblu committed

  struct Job {
    Job() {}
Seblu's avatar
Seblu committed
    Job(int, const string &, time_t);
    int pid;
    string name;
    time_t start_time;
    bool operator()(const Job &a, const Job &b);
  };

  inline bool verbose() const { return options.verbose == 2; }
Seblu's avatar
Seblu committed

  Options options;
Seblu's avatar
Seblu committed

Seblu's avatar
Seblu committed
  void run();
Seblu's avatar
Seblu committed
  // friends functions

  friend void sigchild(int);
  friend void sigint(int);
Seblu's avatar
Seblu committed
protected:

  // current socket
  Connection c_;
//   int socket_fd_;
//   FILE* socket_fs_;
Seblu's avatar
Seblu committed

Seblu's avatar
Seblu committed
  // pid list
  typedef std::set<Job, Job> t_job;
  t_job jobs_;
Seblu's avatar
Seblu committed

Seblu's avatar
Seblu committed
  // Options functions
Seblu's avatar
Seblu committed
  void check_options() const;
Seblu's avatar
Seblu committed

  // network functions
//   void disconnect();
//   void send(const char *data, size_t len, bool buf = true);
//   void send(const string str, bool buf = true);
//   void send(long int i);
//   void sendln(const string &s);
//   char *recv(size_t size);
//   void recv(size_t size, const string &filename);
//   char *recvln();
//   void flush();
Seblu's avatar
Seblu committed
  // protocol functions
Seblu's avatar
Seblu committed
  void auth();
Seblu's avatar
Seblu committed
  // commmand functions
Seblu's avatar
Seblu committed
  void cmd_exit();
Seblu's avatar
Seblu committed
  void cmd_version();
  void cmd_list();
  void cmd_status();
  void cmd_killall();
  void cmd_kill(const char *line);
  void cmd_exec(const char *line);
Seblu's avatar
Seblu committed
  void cmd_update();
Seblu's avatar
Seblu committed
  void cmd_file(const char *line);
Seblu's avatar
Seblu committed

  // others functions
Seblu's avatar
Seblu committed
  string md5(const string &file) const;
  void recv2file(size_t size, const string &filename);
  void clean_dir(const string &dir) const;
private:
  static SLDaemon *instance_;

  ~SLDaemon() {}
  SLDaemon(const SLDaemon &) { assert(true); }
  SLDaemon &operator=(const SLDaemon &) { assert(true); return *instance_; }
Seblu's avatar
Seblu committed
};

#endif