2002-06-04 16:26:23 +04:00
|
|
|
#ifndef IPLATFORM_H
|
|
|
|
#define IPLATFORM_H
|
|
|
|
|
|
|
|
#include "IInterface.h"
|
2002-06-11 02:06:45 +04:00
|
|
|
#include "CString.h"
|
2002-06-04 16:26:23 +04:00
|
|
|
|
|
|
|
class IPlatform : public IInterface {
|
|
|
|
public:
|
2002-06-09 01:48:00 +04:00
|
|
|
typedef int (*DaemonFunc)(IPlatform*, int argc, const char** argv);
|
|
|
|
|
2002-06-14 22:08:20 +04:00
|
|
|
enum EResult {
|
|
|
|
kSuccess,
|
|
|
|
kFailed,
|
|
|
|
kAlready
|
|
|
|
};
|
|
|
|
|
2002-06-04 16:26:23 +04:00
|
|
|
// manipulators
|
|
|
|
|
2002-06-09 01:48:00 +04:00
|
|
|
// install/uninstall a daemon. commandLine should *not*
|
|
|
|
// include the name of program as the first argument.
|
2002-06-04 16:26:23 +04:00
|
|
|
// FIXME -- throw on error? will get better error messages that way.
|
2002-06-09 01:48:00 +04:00
|
|
|
virtual bool installDaemon(const char* name,
|
2002-06-11 02:06:45 +04:00
|
|
|
const char* description,
|
|
|
|
const char* pathname,
|
|
|
|
const char* commandLine) = 0;
|
2002-06-14 22:08:20 +04:00
|
|
|
virtual EResult uninstallDaemon(const char* name) = 0;
|
2002-06-04 16:26:23 +04:00
|
|
|
|
2002-06-14 22:08:20 +04:00
|
|
|
// daemonize. this should call installDaemonLogger(). returns
|
|
|
|
// true iff successful. the name is the name of the daemon.
|
2002-06-09 01:48:00 +04:00
|
|
|
|
|
|
|
// daemonize. this should have the side effect of sending log
|
|
|
|
// messages to a system message logger since messages can no
|
|
|
|
// longer go to the console. name is the name of the daemon.
|
|
|
|
// once daemonized, func is invoked and daemonize returns when
|
|
|
|
// and what func does. daemonize() returns -1 on error.
|
|
|
|
//
|
|
|
|
// exactly what happens when daemonizing depends on the platform.
|
|
|
|
// unix:
|
|
|
|
// detaches from terminal. func gets one argument, the name
|
|
|
|
// passed to daemonize().
|
|
|
|
// win32:
|
|
|
|
// becomes a service. argument 0 is the name of the service
|
|
|
|
// and the rest are the arguments passed to StartService().
|
|
|
|
// func is only called when the service is actually started.
|
|
|
|
// func must behave like a proper ServiceMain() function; in
|
|
|
|
// particular, it must call RegisterServiceCtrlHandler() and
|
|
|
|
// SetServiceStatus().
|
|
|
|
virtual int daemonize(const char* name, DaemonFunc func) = 0;
|
|
|
|
|
2002-06-14 22:08:20 +04:00
|
|
|
// directs CLog to send messages to the daemon log. used when
|
|
|
|
// messages should no longer go to the console. name is used
|
|
|
|
// in the log to identify this process.
|
|
|
|
virtual void installDaemonLogger(const char* name) = 0;
|
|
|
|
|
2002-06-04 16:26:23 +04:00
|
|
|
// accessors
|
|
|
|
|
|
|
|
// find the basename in the given pathname
|
|
|
|
virtual const char* getBasename(const char* pathname) const = 0;
|
|
|
|
|
|
|
|
// get the user's home directory. returns the empty string if
|
|
|
|
// this cannot be determined.
|
|
|
|
virtual CString getUserDirectory() const = 0;
|
|
|
|
|
|
|
|
// get the system configuration file directory
|
|
|
|
virtual CString getSystemDirectory() const = 0;
|
|
|
|
|
|
|
|
// concatenate pathname components with a directory separator
|
|
|
|
// between them. this should not check if the resulting path
|
|
|
|
// is longer than allowed by the system. we'll rely on the
|
|
|
|
// system calls to tell us that.
|
|
|
|
virtual CString addPathComponent(
|
2002-06-11 02:06:45 +04:00
|
|
|
const CString& prefix,
|
|
|
|
const CString& suffix) const = 0;
|
2002-06-04 16:26:23 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|