documentation for class Daemon added.
This commit is contained in:
@@ -32,10 +32,10 @@ Daemon& Daemon::Instance()
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Daemon::run(const char* file)
|
void Daemon::run(const char* pidfile)
|
||||||
{
|
{
|
||||||
m_status = false;
|
m_status = false;
|
||||||
m_pidfile = file;
|
m_pidfile = pidfile;
|
||||||
m_pidfd = 0;
|
m_pidfd = 0;
|
||||||
|
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
|||||||
+38
-6
@@ -20,27 +20,59 @@
|
|||||||
#ifndef LIBUTILS_DAEMON_H_
|
#ifndef LIBUTILS_DAEMON_H_
|
||||||
#define LIBUTILS_DAEMON_H_
|
#define LIBUTILS_DAEMON_H_
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief class to daemonize a process.
|
||||||
|
*/
|
||||||
class Daemon
|
class Daemon
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief create an daemon instance and return the reference.
|
||||||
|
* @return the reference to instance.
|
||||||
|
*/
|
||||||
static Daemon& Instance();
|
static Daemon& Instance();
|
||||||
~Daemon() {}
|
|
||||||
|
|
||||||
void run(const char* file);
|
/**
|
||||||
|
* @brief daemonize act process.
|
||||||
|
* @param pidfile the name of the pid file.
|
||||||
|
*/
|
||||||
|
void run(const char* pidfile);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief stop daemon and delete the pid file.
|
||||||
|
*/
|
||||||
void stop() { pidfile_close(); }
|
void stop() { pidfile_close(); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief show actual status if daemonize.
|
||||||
|
* @return true if process is a daemon.
|
||||||
|
*/
|
||||||
bool status() { return m_status; }
|
bool status() { return m_status; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_status;
|
/** private constructor - singleton pattern */
|
||||||
const char* m_pidfile;
|
|
||||||
int m_pidfd;
|
|
||||||
|
|
||||||
Daemon() {}
|
Daemon() {}
|
||||||
Daemon(const Daemon&);
|
Daemon(const Daemon&);
|
||||||
Daemon& operator=(const Daemon&);
|
Daemon& operator=(const Daemon&);
|
||||||
|
|
||||||
|
/** status of process; true if we are a daemon */
|
||||||
|
bool m_status;
|
||||||
|
/** name of the pid file*/
|
||||||
|
const char* m_pidfile;
|
||||||
|
/** file descriptor of the pid file */
|
||||||
|
int m_pidfd;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief creates a pid file for process.
|
||||||
|
* @return true if success.
|
||||||
|
*/
|
||||||
bool pidfile_open();
|
bool pidfile_open();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief close and delete the pid file.
|
||||||
|
* @return true if success.
|
||||||
|
*/
|
||||||
bool pidfile_close();
|
bool pidfile_close();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user