summaryrefslogtreecommitdiffstats
path: root/src/pvsDaemon.cpp
diff options
context:
space:
mode:
authorJohann Latocha2010-08-28 03:17:08 +0200
committerJohann Latocha2010-08-28 03:17:08 +0200
commitca61d21c6defb9553234c1fa5b0979c46542c676 (patch)
tree610c5b1457d968135c1b70dfc8150737263e8922 /src/pvsDaemon.cpp
parentSome refactoring (diff)
downloadpvs-ca61d21c6defb9553234c1fa5b0979c46542c676.tar.gz
pvs-ca61d21c6defb9553234c1fa5b0979c46542c676.tar.xz
pvs-ca61d21c6defb9553234c1fa5b0979c46542c676.zip
Enhancement #587
Diffstat (limited to 'src/pvsDaemon.cpp')
-rwxr-xr-xsrc/pvsDaemon.cpp132
1 files changed, 59 insertions, 73 deletions
diff --git a/src/pvsDaemon.cpp b/src/pvsDaemon.cpp
index e9479df..b23bc57 100755
--- a/src/pvsDaemon.cpp
+++ b/src/pvsDaemon.cpp
@@ -9,14 +9,12 @@
#include "src/core/pvsChatClient.h"
PVS *mainClient = NULL;
-
-// This define works as a switch whether to run as deamon or regular app
-#define as_daemon
+QTextStream qout(stdout);
/// VERSION_STRING is defined in src/version.h
void printVersion(bool doExit)
{
-
+ QTextStream qout(stdout);
printf("Version:\t"VERSION_STRING"\n");
if (doExit)
exit(0);
@@ -25,30 +23,31 @@ void printVersion(bool doExit)
/// outputs the full help text
void printHelp()
{
- printf("**************************************************************\n");
- printf("\nPool Video Switch Client\n");
- printf("**************************************************************\n");
- printVersion(false);
- printf("**************************************************************\n");
- printf("Usage:\tpoolVSClient <<option> <value>, ... >\n\n");
- printf("Options:\n\n");
- printf("-vncScriptFile <fullpath\\filename>\n\tSpecifies a custom location for the vnc-start/stop-script.\n\tIf not specified, ~/.pvs/pvs-vncsrv is expected.\n\n");
- printf("-freq <seconds>\n\tSpecifies how long to wait until a reconnection attempt is made.\n\tDefault is 5.\n\n");
- printf("-port <port>\n\tSpecifies on which port to run.\n\tDefault is %d.\n\n", SERVER_PORT_INT);
- printf("-h or --help\n\t Shows this help text and exits.\n\n");
- printf("-v or --version\n\t Shows the current version and exits.\n");
- printf(
- "-c <string command>:<string value> \n\t Sends the command and the optional value to a running PVS-Client.\n\t Command and value may not contain spaces or colons.\n\t The dividing colon is mandatory.\n");
- printf("-commands: \n\tPrints out available commands to use with -c . \n ");
- printf("**************************************************************\n");
+ qout << "**************************************************************\n";
+ qout << "Pool Video Switch Client\n";
+ qout << "**************************************************************\n";
+ qout << QObject::tr("Version: ") << VERSION_STRING << "\n";
+ qout << "**************************************************************\n";
+ qout << QObject::tr("Usage:") << "\tpoolVSClient " << QObject::tr("<<option> <value>, ... >") << "\n\n";
+ qout << QObject::tr("Options:") << "\n\n";
+ qout << QObject::tr("-vncScriptFile <fullpath\\filename>") << "\n\t" << QObject::tr("Specifies a custom location for the vnc-start/stop-script.")<< "\n\t" << QObject::tr("If not specified, /usr/bin/pvs-vncsrv is expected.") << "\n\n";
+ qout << QObject::tr("-freq <seconds>") << "\n\t" << QObject::tr("Specifies how long to wait until a reconnection attempt is made.") << "\n\t" << QObject::tr("Default is 5.") << "\n\n";
+ qout << QObject::tr("-port <port>") << "\n\t" << QObject::tr("Specifies on which port to run.") << "\n\t" << QObject::tr("Default is ") << SERVER_PORT_INT << ".\n\n";
+ qout << QObject::tr("-h or --help") << "\n\t" << QObject::tr("Shows this help text and exits.") << "\n\n";
+ qout << QObject::tr("-v or --version") << "\n\t" << QObject::tr("Shows the current version and exits.") << "\n";
+ qout << QObject::tr("-d or --daemon") << "\n\t" << QObject::tr("Start as daemon.") << "\n";
+ qout << QObject::tr("-c <string command>:<string value>") << "\n\t" << QObject::tr("Sends the command and the optional value to a running PVS-Client.") << "\n\t" << QObject::tr("Command and value may not contain spaces or colons.") << "\n\t" << QObject::tr("The dividing colon is mandatory.") << "\n";
+ qout << "-commands: \n\t" << QObject::tr("Prints out available commands to use with -c.") << "\n";
+ qout << "**************************************************************\n";
+ qout.flush();
exit(0);
}
/// outputs a brief help text
void printNotice()
{
- printf(
- "Use -h or --help to get a listing of all options.\n-v or --version gives you the current version.\n\n");
+ qout << QObject::tr("Use -h or --help to get a listing of all options.\n-v or --version gives you the current version.\n\n");
+ qout.flush();
}
void printCommands()
@@ -64,6 +63,7 @@ void printCommands()
///
int main(int argc, char** argv)
{
+ bool daemon = false;
int frequency = 5;
int port = -1;
@@ -99,7 +99,6 @@ int main(int argc, char** argv)
exit(0);
}
- printf("UDS Communicator is running.\n");
int option_index = 0;
while (1)
@@ -109,6 +108,7 @@ int main(int argc, char** argv)
{ "help", no_argument, 0, 'h' },
{ "commands", no_argument, 0, 'o' },
{ "version", no_argument, 0, 'v' },
+ { "daemon", no_argument, 0, 'd' },
{ "port", required_argument, 0, 'p' },
{ "freq", required_argument, 0, 'f' },
{ "client", required_argument, 0, 'e' },
@@ -117,7 +117,7 @@ int main(int argc, char** argv)
};
/* getopt_long stores the option index here. */
- int c = getopt_long(argc, argv, "hvoc:f:e:s:p:", long_options,
+ int c = getopt_long(argc, argv, "hovdc:f:e:s:p:", long_options,
&option_index);
option_index++;
if (c == -1)
@@ -134,6 +134,9 @@ int main(int argc, char** argv)
case 'v':
printVersion(true);
break;
+ case 'd':
+ daemon = true;
+ break;
case 'c':
{
if (option_index + 1 < argc)
@@ -297,58 +300,41 @@ int main(int argc, char** argv)
ConsoleLog setLogName(QString("log.client"));
ConsoleLog writeLine(QString("PVS-Client started."));
-#ifdef as_daemon
-
- /*Alex: neu schreiben als pvsdaemon_win32.cpp und minimieren in Task-Leiste*/
- #ifndef __WIN32__
- /* Our process ID and Session ID */
- pid_t pid, sid;
-
- /* Fork off the parent process */
- pid = fork();
- if (pid < 0)
+ if (daemon)
{
- exit(-1);
- }
- /* If we got a good PID, then
- we can exit the parent process. */
- if (pid > 0)
- {
- exit(0);
+ #ifndef __WIN32__
+ pid_t pid, sid; // our process ID and session ID
+
+ // fork off the parent process
+ pid = fork();
+ if (pid < 0)
+ exit(-1);
+
+ // if we got a good PID, then we can exit the parent process.
+ if (pid > 0)
+ exit(0);
+
+ // change the file mode mask
+ umask(0);
+
+ // create a new SID for the child process
+ sid = setsid();
+ if (sid < 0)
+ exit(-1);
+
+ // change the current working directory
+ if ((chdir("/")) < 0)
+ exit(-1);
+
+ // close out the standard file descriptors
+ close(STDIN_FILENO);
+ freopen ((QString(getHomeDir()).append(QString("/.pvs/dump"))).toUtf8()
+ .data(),"w",stdout);
+ //close(STDOUT_FILENO);
+ close(STDERR_FILENO);
+ #endif /*__WIN32__*/
}
- /* Change the file mode mask */
- umask(0);
-
- /* Open any logs here */
-
- /* Create a new SID for the child process */
- sid = setsid();
- if (sid < 0)
- {
- /* Log the failure */
- exit(-1);
- }
-
- /* Change the current working directory */
- if ((chdir("/")) < 0)
- {
- /* Log the failure */
- exit(-1);
- }
-
- /* Close out the standard file descriptors */
- close(STDIN_FILENO);
- freopen ((QString(getHomeDir()).append(QString("/.pvs/dump"))).toUtf8().data(),"w",stdout);
- //close(STDOUT_FILENO);
- close(STDERR_FILENO);
- #endif /*__WIN32__*/
- /* Daemon-specific initialization goes here */
-
- /* The Big Loop */
-
-#endif
-
mainClient = new PVS();
PVSSettingsManager::getManager()->setConfigFile(getPolicyFilePath("clientconf"));
com.getDispatcher()->addListener("*", mainClient, &PVS::onDaemonCommand);