summaryrefslogtreecommitdiffstats
path: root/Master/Masterarbeit/src/XorayaPluginExecutor/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Master/Masterarbeit/src/XorayaPluginExecutor/main.cpp')
-rw-r--r--Master/Masterarbeit/src/XorayaPluginExecutor/main.cpp108
1 files changed, 108 insertions, 0 deletions
diff --git a/Master/Masterarbeit/src/XorayaPluginExecutor/main.cpp b/Master/Masterarbeit/src/XorayaPluginExecutor/main.cpp
new file mode 100644
index 0000000..c2e131c
--- /dev/null
+++ b/Master/Masterarbeit/src/XorayaPluginExecutor/main.cpp
@@ -0,0 +1,108 @@
+/*!
+ * \file main.cpp
+ * \author S. Eisenhauer
+ * \date 31.08.2011
+ * \brief Application startup
+ */
+
+/*!
+ * \mainpage XORAYA Plugin executor
+ * This is the main application running on the XORAYA connect to integrate with CanEasy.
+*/
+
+#include <errno.h>
+#include <sys/mman.h>
+#include <string.h>
+#include <boost/thread.hpp>
+#include <boost/bind.hpp>
+
+#include "CPluginExecutor.h"
+#include "global.h"
+
+/*!
+* \brief Allocates a safe stack
+*/
+void prefault_stack()
+{
+ unsigned char aucDummy[nMAX_SAFE_STACK];
+
+ memset(aucDummy, 0, nMAX_SAFE_STACK);
+ return;
+}
+
+/*!
+* \brief Prevents memory of this process to be swapped to disc
+* \warning process needs root privileges for this to work correctly
+*/
+void lockmem()
+{
+ int res = 0;
+ if( (res = mlockall(MCL_CURRENT|MCL_FUTURE)) != 0)
+ {
+ ERROR_PRINT("mlockall failed: %d errno: %d",res,errno);
+ //exit(-2);
+ }
+}
+
+/*!
+* \brief initialization code
+*/
+void init()
+{
+ lockmem();
+ prefault_stack();
+}
+
+/*!
+* \brief application starts here
+* \param[in] argc number of arguments passed to process
+* \param[in] argv the arguments
+* \return exit code, 0 on success
+*/
+int main(int argc, char* argv[])
+{
+ int res = 0;
+ int schedulerPolicy;
+ sched_param sp;
+
+ init();
+
+ static CPluginExecutor xPluginExec;
+ boost::thread xExecThread(
+ boost::function<void()>(
+ boost::bind(&CPluginExecutor::vRun,boost::ref(xPluginExec))
+ )
+ );
+
+ if( argc == 2)
+ {
+ if( strcmp(argv[1],"RT") == 0 )
+ {
+ schedulerPolicy = SCHED_FIFO;
+ sp.sched_priority = tenPrio::nenRT ; // rt priority
+ if(pthread_setschedparam(xExecThread.native_handle(), schedulerPolicy, &sp))
+ {
+ ERROR_PRINT("pthread_setschedparam failed. Errno: %d",errno);
+ }
+ }
+ }
+
+ if( (res = pthread_getschedparam(xExecThread.native_handle(),&schedulerPolicy,&sp)) != 0 )
+ {
+ ERROR_PRINT("pthread_getschedparam failed: %d errno: %d",res,errno);
+ }
+ else
+ {
+ DEBUG_PRINT("executor thread prio: %d scheduler: %s"
+ ,sp.sched_priority
+ ,(schedulerPolicy==SCHED_OTHER)?"SCHED_OTHER":
+ (schedulerPolicy==SCHED_FIFO)?"SCHED_FIFO":
+ (schedulerPolicy==SCHED_RR)?"SCHED_RR":"other");
+ }
+
+ xExecThread.join();
+ DEBUG_PRINT("exiting");
+ return 0;
+}
+
+