2002-08-02 23:57:46 +04:00
|
|
|
/*
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
|
|
|
* Copyright (C) 2002 Chris Schoeneman
|
|
|
|
*
|
|
|
|
* This package is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* found in the file COPYING that should have accompanied this file.
|
|
|
|
*
|
|
|
|
* This package 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.
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
2002-07-29 21:03:55 +04:00
|
|
|
//! Platform dependent functions interface
|
|
|
|
/*!
|
|
|
|
This interface provides methods to query platform specific data and
|
|
|
|
perform operations that are inherently non-portable.
|
|
|
|
*/
|
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-07-29 21:03:55 +04:00
|
|
|
//! Uninstall result codes
|
2002-06-14 22:08:20 +04:00
|
|
|
enum EResult {
|
2002-07-29 21:03:55 +04:00
|
|
|
kSuccess, //!< Uninstall succeeded
|
|
|
|
kFailed, //!< Uninstall failed
|
|
|
|
kAlready //!< Not installed
|
2002-06-14 22:08:20 +04:00
|
|
|
};
|
|
|
|
|
2002-07-29 21:03:55 +04:00
|
|
|
//! @name manipulators
|
|
|
|
//@{
|
2002-06-04 16:26:23 +04:00
|
|
|
|
2002-07-29 21:03:55 +04:00
|
|
|
//! Install daemon
|
|
|
|
/*!
|
|
|
|
Install a daemon. \c name is the name of the daemon passed to the
|
|
|
|
system and \c description is a short human readable description of
|
|
|
|
the daemon. \c pathname is the path to the daemon executable.
|
|
|
|
\c commandLine should \b not include the name of program as the
|
2002-09-02 21:30:04 +04:00
|
|
|
first argument. If \c allUsers is true then the daemon will be
|
|
|
|
installed to start at boot time, otherwise it will be installed to
|
|
|
|
start when the current user logs in.
|
2002-07-29 21:03:55 +04:00
|
|
|
*/
|
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,
|
2002-09-02 21:30:04 +04:00
|
|
|
const char* commandLine,
|
|
|
|
bool allUsers) = 0;
|
|
|
|
|
2002-07-29 21:03:55 +04:00
|
|
|
//! Uninstall daemon
|
|
|
|
/*!
|
|
|
|
Uninstall a daemon.
|
|
|
|
*/
|
2002-09-02 21:30:04 +04:00
|
|
|
virtual EResult uninstallDaemon(const char* name, bool allUsers) = 0;
|
2002-06-04 16:26:23 +04:00
|
|
|
|
2002-07-29 21:03:55 +04:00
|
|
|
//! Daemonize the process
|
|
|
|
/*!
|
|
|
|
Daemonize. This should call installDaemonLogger(). Returns
|
|
|
|
true iff successful. \c name is the name of the daemon.
|
|
|
|
Once daemonized, \c func is invoked and daemonize returns when
|
|
|
|
and what it does. daemonize() returns -1 on error.
|
|
|
|
|
|
|
|
Exactly what happens when daemonizing depends on the platform.
|
|
|
|
<ul>
|
|
|
|
<li>unix:
|
|
|
|
Detaches from terminal. \c func gets passed one argument, the
|
|
|
|
name passed to daemonize().
|
|
|
|
<li>win32:
|
|
|
|
Becomes a service. Argument 0 is the name of the service
|
|
|
|
and the rest are the arguments passed to StartService().
|
|
|
|
\c func is only called when the service is actually started.
|
|
|
|
\c func must behave like a proper ServiceMain() function; in
|
|
|
|
particular, it must call RegisterServiceCtrlHandler() and
|
|
|
|
SetServiceStatus().
|
|
|
|
</ul>
|
|
|
|
*/
|
2002-06-09 01:48:00 +04:00
|
|
|
virtual int daemonize(const char* name, DaemonFunc func) = 0;
|
|
|
|
|
2002-07-29 21:03:55 +04:00
|
|
|
//! Install daemon logger
|
|
|
|
/*!
|
|
|
|
Directs CLog to send messages to the daemon log. Used when
|
|
|
|
messages should no longer go to the console. \c name is used
|
|
|
|
in the log to identify this process.
|
|
|
|
*/
|
2002-06-14 22:08:20 +04:00
|
|
|
virtual void installDaemonLogger(const char* name) = 0;
|
|
|
|
|
2002-07-29 21:03:55 +04:00
|
|
|
//@}
|
|
|
|
//! @name accessors
|
|
|
|
//@{
|
2002-06-04 16:26:23 +04:00
|
|
|
|
2002-09-02 21:30:04 +04:00
|
|
|
//! Check if user has permission to install the daemon
|
|
|
|
/*!
|
|
|
|
Returns true iff the caller has permission to install or
|
|
|
|
uninstall the daemon. Note that even if this method returns
|
|
|
|
true it's possible that installing/uninstalling the service
|
|
|
|
may still fail. This method ignores whether or not the
|
|
|
|
service is already installed.
|
|
|
|
*/
|
|
|
|
virtual bool canInstallDaemon(const char* name,
|
|
|
|
bool allUsers) const = 0;
|
|
|
|
|
|
|
|
//! Check if the daemon is installed
|
|
|
|
/*!
|
|
|
|
Returns true iff the daemon is installed.
|
|
|
|
*/
|
|
|
|
virtual bool isDaemonInstalled(const char* name,
|
|
|
|
bool allUsers) const = 0;
|
|
|
|
|
2002-07-29 21:03:55 +04:00
|
|
|
//! Extract base name
|
|
|
|
/*!
|
|
|
|
Find the base name in the given \c pathname.
|
|
|
|
*/
|
2002-06-04 16:26:23 +04:00
|
|
|
virtual const char* getBasename(const char* pathname) const = 0;
|
|
|
|
|
2002-07-29 21:03:55 +04:00
|
|
|
//! Get user's home directory
|
|
|
|
/*!
|
|
|
|
Returns the user's home directory. Returns the empty string if
|
|
|
|
this cannot be determined.
|
|
|
|
*/
|
2002-06-04 16:26:23 +04:00
|
|
|
virtual CString getUserDirectory() const = 0;
|
|
|
|
|
2002-07-29 21:03:55 +04:00
|
|
|
//! Get system directory
|
|
|
|
/*!
|
|
|
|
Returns the ussystem configuration file directory.
|
|
|
|
*/
|
2002-06-04 16:26:23 +04:00
|
|
|
virtual CString getSystemDirectory() const = 0;
|
|
|
|
|
2002-07-29 21:03:55 +04:00
|
|
|
//! Concatenate path components
|
|
|
|
/*!
|
|
|
|
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.
|
|
|
|
*/
|
2002-06-04 16:26:23 +04:00
|
|
|
virtual CString addPathComponent(
|
2002-06-11 02:06:45 +04:00
|
|
|
const CString& prefix,
|
|
|
|
const CString& suffix) const = 0;
|
2002-07-29 21:03:55 +04:00
|
|
|
|
|
|
|
//@}
|
2002-06-04 16:26:23 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|