You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.cpp 942B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include <QCoreApplication>
  2. #include <QDebug>
  3. #include <unistd.h>
  4. #include <QSettings>
  5. #include "mainclass.h"
  6. void printUsage()
  7. {
  8. qDebug()<<"Usage: netsould";
  9. qDebug()<<"\t-h, --help \t\t print this help.";
  10. qDebug()<<"\t-p, --pid file \t\t indicate the file path to write de pid. The pid will be written when the daemon is connected to the netsoul server, and a blank file when disconnected.";
  11. }
  12. int main(int argc, char *argv[])
  13. {
  14. QCoreApplication a(argc, argv);
  15. MainClass m;
  16. for(int i = 1; i < qApp->argc(); ++i)
  17. {
  18. QString c = qApp->arguments().at(i);
  19. if(c == "-p" || c == "--pid")
  20. {
  21. if(qApp->argc() > i + 1)
  22. m.setPidFile(qApp->arguments().at(++i));
  23. else
  24. {
  25. printUsage();
  26. return 1;
  27. }
  28. }
  29. else
  30. {
  31. printUsage();
  32. return 1;
  33. }
  34. }
  35. while(!m.start())
  36. {
  37. qDebug()<<"[Error] Failed to start. Trying again in 5 seconds...";
  38. sleep(5);
  39. }
  40. qDebug()<<"[Info ] Daemon started";
  41. return a.exec();
  42. }