From 3d3deae9c7dbce035fd10cc0dcd92d54ee3039c7 Mon Sep 17 00:00:00 2001 From: Dario Date: Fri, 27 Sep 2019 21:29:27 +0200 Subject: [PATCH] adding task logic from Universum Game Engine --- src/cpp/tasks/CPUSheduler.cpp | 76 ++++++++++++++++ src/cpp/tasks/CPUSheduler.h | 91 +++++++++++++++++++ src/cpp/tasks/CPUShedulerThread.cpp | 57 ++++++++++++ src/cpp/tasks/CPUShedulerThread.h | 78 ++++++++++++++++ src/cpp/tasks/CPUTask.cpp | 32 +++++++ src/cpp/tasks/CPUTask.h | 71 +++++++++++++++ src/cpp/tasks/MultithreadContainer.h | 54 ++++++++++++ src/cpp/tasks/MultithreadQueue.h | 86 ++++++++++++++++++ src/cpp/tasks/PrepaireEmailTask.cpp | 0 src/cpp/tasks/PrepaireEmailTask.h | 0 src/cpp/tasks/SendEmailTask.cpp | 16 ++++ src/cpp/tasks/SendEmailTask.h | 21 +++++ src/cpp/tasks/Task.cpp | 64 ++++++++++++++ src/cpp/tasks/Task.h | 127 +++++++++++++++++++++++++++ src/cpp/tasks/Thread.cpp | 95 ++++++++++++++++++++ src/cpp/tasks/Thread.h | 80 +++++++++++++++++ src/cpp/tasks/WriteIntoDBTask.cpp | 16 ++++ src/cpp/tasks/WriteIntoDBTask.h | 21 +++++ src/cpsp/dashboard.cpsp | 25 ++++++ src/cpsp/emailOptIn.cpsp | 93 ++++++++++++++++++++ 20 files changed, 1103 insertions(+) create mode 100644 src/cpp/tasks/CPUSheduler.cpp create mode 100644 src/cpp/tasks/CPUSheduler.h create mode 100644 src/cpp/tasks/CPUShedulerThread.cpp create mode 100644 src/cpp/tasks/CPUShedulerThread.h create mode 100644 src/cpp/tasks/CPUTask.cpp create mode 100644 src/cpp/tasks/CPUTask.h create mode 100644 src/cpp/tasks/MultithreadContainer.h create mode 100644 src/cpp/tasks/MultithreadQueue.h create mode 100644 src/cpp/tasks/PrepaireEmailTask.cpp create mode 100644 src/cpp/tasks/PrepaireEmailTask.h create mode 100644 src/cpp/tasks/SendEmailTask.cpp create mode 100644 src/cpp/tasks/SendEmailTask.h create mode 100644 src/cpp/tasks/Task.cpp create mode 100644 src/cpp/tasks/Task.h create mode 100644 src/cpp/tasks/Thread.cpp create mode 100644 src/cpp/tasks/Thread.h create mode 100644 src/cpp/tasks/WriteIntoDBTask.cpp create mode 100644 src/cpp/tasks/WriteIntoDBTask.h create mode 100644 src/cpsp/dashboard.cpsp create mode 100644 src/cpsp/emailOptIn.cpsp diff --git a/src/cpp/tasks/CPUSheduler.cpp b/src/cpp/tasks/CPUSheduler.cpp new file mode 100644 index 000000000..3620dd3b8 --- /dev/null +++ b/src/cpp/tasks/CPUSheduler.cpp @@ -0,0 +1,76 @@ +#include "CPUSheduler.h" +#include "CPUShedulerThread.h" +#include "CPUTask.h" + +namespace UniLib { + namespace controller { + + CPUSheduler::CPUSheduler(uint8_t threadCount, const char* name) + : mThreads(new CPUShedulerThread*[threadCount]), mThreadCount(threadCount), mName(name) + { + char nameBuffer[10]; memset(nameBuffer, 0, 10); + uint8_t len = min(strlen(name), 7); + memcpy(nameBuffer, name, len); + for(int i = 0; i < threadCount; i++) { + sprintf(&nameBuffer[len], "%.2d", i); + mThreads[i] = new CPUShedulerThread(this, nameBuffer); + } + } + + CPUSheduler::~CPUSheduler() + { + for(int i = 0; i < mThreadCount; i++) { + if (mThreads[i]) { + delete mThreads[i]; + } + } + delete[] mThreads; + mThreadCount = 0; + } + + int CPUSheduler::sheduleTask(TaskPtr task) + { + CPUShedulerThread* t = NULL; + // look at free worker threads + if(task->isAllParentsReady() && mFreeWorkerThreads.pop(t)) { + // gave him the new task + t->setNewTask(task); + } else { + // else put task to pending queue + mPendingTasksMutex.lock(); + mPendingTasks.push_back(task); + mPendingTasksMutex.unlock(); + } + return 0; + } + TaskPtr CPUSheduler::getNextUndoneTask(CPUShedulerThread* Me) + { + // look at pending tasks + TaskPtr task; + mPendingTasksMutex.lock(); + for (std::list::iterator it = mPendingTasks.begin(); it != mPendingTasks.end(); it++) { + if ((*it)->isAllParentsReady()) { + task = *it; + mPendingTasks.erase(it); + mPendingTasksMutex.unlock(); + return task; + } + } + mPendingTasksMutex.unlock(); + // push thread to worker queue + if (Me) { + mFreeWorkerThreads.push(Me); + } + + return TaskPtr(); + } + void CPUSheduler::checkPendingTasks() + { + TaskPtr task = getNextUndoneTask(NULL); + if (!task.isNull()) { + sheduleTask(task); + } + } + + } +} \ No newline at end of file diff --git a/src/cpp/tasks/CPUSheduler.h b/src/cpp/tasks/CPUSheduler.h new file mode 100644 index 000000000..28941f699 --- /dev/null +++ b/src/cpp/tasks/CPUSheduler.h @@ -0,0 +1,91 @@ +/*/************************************************************************* +* * +* UniversumLib, collection of classes for generating and go through a * +* whole universe. It is for my Gameproject Spacecraft * +* Copyright (C) 2014, 2015, 2016, 2017 Dario Rekowski. * +* Email: ***REMOVED*** Web: ***REMOVED*** * +* * +* This program is free software: you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation, either version 3 of the License, or * +* any later version. * +* * +* This program 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. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program. If not, see . * +* * +***************************************************************************/ + +/*! + * + * \author: Dario Rekowski + * + * \date: 27.09.15 + * + * \desc: Scheduler for CPU Tasks, multiple threads + */ + +#ifndef __DR_UNIVERSUM_LIB_CONTROLLER_CPU_SHEDULER_H__ +#define __DR_UNIVERSUM_LIB_CONTROLLER_CPU_SHEDULER_H__ + +//#include "UniversumLib.h" +#include +#include +#include + +#include "Poco/AutoPtr.h" + +#include "MultithreadQueue.h" + +namespace UniLib { + namespace controller { + + class Task; + typedef Poco::AutoPtr TaskPtr; + + class CPUShedulerThread; + + class CPUSheduler + { + public: + // \param threadCount how many threads should be used + // \param name name for threads (only first 7 chars are used for thread name) + CPUSheduler(uint8_t threadCount, const char* name); + virtual ~CPUSheduler(); + + int sheduleTask(TaskPtr task); + void checkPendingTasks(); +#ifdef _UNI_LIB_DEBUG + CPUShedulerThread** getThreads(u8& count) {count = mThreadCount; return mThreads;}; +#endif + // called from scheduler thread if he wants a new task to do + // return null if no task pending, putting thread in wait queue, + // to inform him if a new task is ready for him + TaskPtr getNextUndoneTask(CPUShedulerThread* Me); + + inline uint8_t getThreadCount() { return mThreadCount; } + protected: + + + private: + // worker threads + CPUShedulerThread** mThreads; + uint8_t mThreadCount; + std::string mName; + // free worker + lib::MultithreadQueue mFreeWorkerThreads; + // work to do + //lib::MultithreadQueue mPendingTasks; + std::list mPendingTasks; + lib::MultithreadContainer mPendingTasksMutex; + + }; + } +} + +#endif //__DR_UNIVERSUM_LIB_CONTROLLER_CPU_SHEDULER_H__ + \ No newline at end of file diff --git a/src/cpp/tasks/CPUShedulerThread.cpp b/src/cpp/tasks/CPUShedulerThread.cpp new file mode 100644 index 000000000..9f11c3ade --- /dev/null +++ b/src/cpp/tasks/CPUShedulerThread.cpp @@ -0,0 +1,57 @@ +#include "CPUShedulerThread.h" +#include "CPUSheduler.h" +#include "Task.h" +//#include "debug/CPUSchedulerTasksLog.h" + +#ifdef _UNI_LIB_DEBUG +#include "lib/TimeCounter.h" +#endif //_UNI_LIB_DEBUG + + +namespace UniLib { + namespace controller { + CPUShedulerThread::CPUShedulerThread(CPUSheduler* parent, const char* name) + : Thread(name), mParent(parent) + { +#ifdef _UNI_LIB_DEBUG + mName = name; +#endif + mWaitingTask = mParent->getNextUndoneTask(this); + + } + + CPUShedulerThread::~CPUShedulerThread() + { + } + + int CPUShedulerThread::ThreadFunction() + { + while(!mWaitingTask.isNull()) + { + +#ifdef _UNI_LIB_DEBUG + lib::TimeCounter counter; + debug::CPUShedulerTasksLog* l = debug::CPUShedulerTasksLog::getInstance(); + const char* name = mWaitingTask->getName(); + l->addTaskLogEntry((HASH)mWaitingTask.getResourcePtrHolder(), mWaitingTask->getResourceType(), mName.data(), name); +#endif + mWaitingTask->run(); +#ifdef _UNI_LIB_DEBUG + l->removeTaskLogEntry((HASH)mWaitingTask.getResourcePtrHolder()); + SpeedLog.writeToLog("%s used on thread: %s by Task: %s of: %s", + counter.string().data(), mName.data(), mWaitingTask->getResourceType(), name); +#endif + mWaitingTask = mParent->getNextUndoneTask(this); + } + return 0; + } + + void CPUShedulerThread::setNewTask(TaskPtr cpuTask) + { + threadLock(); + mWaitingTask = cpuTask; + threadUnlock(); + condSignal(); + } + } +} \ No newline at end of file diff --git a/src/cpp/tasks/CPUShedulerThread.h b/src/cpp/tasks/CPUShedulerThread.h new file mode 100644 index 000000000..f0a198447 --- /dev/null +++ b/src/cpp/tasks/CPUShedulerThread.h @@ -0,0 +1,78 @@ +/*/************************************************************************* +* * +* UniversumLib, collection of classes for generating and go through a * +* whole universe. It is for my Gameproject Spacecraft * +* Copyright (C) 2014, 2015, 2016, 2017 Dario Rekowski. * +* Email: ***REMOVED*** Web: ***REMOVED*** * +* * +* This program is free software: you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation, either version 3 of the License, or * +* any later version. * +* * +* This program 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. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program. If not, see . * +* * +***************************************************************************/ + +/*! + * + * \author: Dario Rekowski + * + * \date: 27.09.15 + * + * \desc: CPU Scheduler Thread, one of multiple threads of CPU Scheduler + */ + +#ifndef __DR_UNIVERSUM_LIB_CONTROLLER_CPU_SHEDULER_THREAD_H__ +#define __DR_UNIVERSUM_LIB_CONTROLLER_CPU_SHEDULER_THREAD_H__ + +#include "Thread.h" +#include "Poco/AutoPtr.h" + +namespace UniLib { + namespace controller { + + class Task; + typedef Poco::AutoPtr TaskPtr; + class CPUSheduler; + + + + class CPUShedulerThread : public lib::Thread + { + public: + CPUShedulerThread(CPUSheduler* parent, const char* name); + virtual ~CPUShedulerThread(); + + //! \brief will be called every time from thread, when condSignal was called + //! will be called from thread with locked working mutex,
+ //! mutex will be unlock after calling this function + //! \return if return isn't 0, thread will exit + virtual int ThreadFunction(); + + void setNewTask(TaskPtr cpuTask); + +#ifdef _UNI_LIB_DEBUG + std::string getName() {return mName;} +#endif + protected: +#ifdef _UNI_LIB_DEBUG + std::string mName; +#endif + + private: + TaskPtr mWaitingTask; + CPUSheduler* mParent; + + }; + } +} + +#endif //__DR_UNIVERSUM_LIB_CONTROLLER_CPU_SHEDULER_THREAD_H__ + \ No newline at end of file diff --git a/src/cpp/tasks/CPUTask.cpp b/src/cpp/tasks/CPUTask.cpp new file mode 100644 index 000000000..5db250faf --- /dev/null +++ b/src/cpp/tasks/CPUTask.cpp @@ -0,0 +1,32 @@ +#include "CPUTask.h" +#include "CPUSheduler.h" + +namespace UniLib { + namespace controller { + CPUTask::CPUTask(CPUSheduler* cpuScheduler, size_t taskDependenceCount) + : Task(taskDependenceCount), mScheduler(cpuScheduler) + { + assert(cpuScheduler); + } + + CPUTask::CPUTask(CPUSheduler* cpuScheduler) + : Task(), mScheduler(cpuScheduler) + { + assert(cpuScheduler); + } + + CPUTask::~CPUTask() + { + + } + + void CPUTask::scheduleTask(TaskPtr own) + { + assert(mScheduler); + if(!isTaskSheduled()) { + mScheduler->sheduleTask(own); + taskScheduled(); + } + } + } +} diff --git a/src/cpp/tasks/CPUTask.h b/src/cpp/tasks/CPUTask.h new file mode 100644 index 000000000..d8762703c --- /dev/null +++ b/src/cpp/tasks/CPUTask.h @@ -0,0 +1,71 @@ +/*/************************************************************************* +* * +* UniversumLib, collection of classes for generating and go through a * +* whole universe. It is for my Gameproject Spacecraft * +* Copyright (C) 2014, 2015, 2016, 2017 Dario Rekowski. * +* Email: ***REMOVED*** Web: ***REMOVED*** * +* * +* This program is free software: you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation, either version 3 of the License, or * +* any later version. * +* * +* This program 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. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program. If not, see . * +* * +***************************************************************************/ + +/*! + * + * \author: Dario Rekowski + * + * \date: 27.09.15 + * + * \desc: One Task for the CPU, only calculation + */ + +#ifndef __DR_UNIVERSUM_LIB_CONTROLLER_CPU_TASK_H__ +#define __DR_UNIVERSUM_LIB_CONTROLLER_CPU_TASK_H__ + +#include "Task.h" +#include "CPUSheduler.h" + +#include "Poco/AutoPtr.h" + +namespace UniLib { + namespace controller { + + class CPUTask; + typedef Poco::AutoPtr CPUTaskPtr; + + class CPUSheduler; + + class CPUTask : public Task + { + public: + CPUTask(CPUSheduler* cpuSheduler, size_t taskDependenceCount); + CPUTask(CPUSheduler* cpuScheduler); + virtual ~CPUTask(); + + virtual const char* getResourceType() const {return "CPUTask";}; + //! \brief return true if task has finished, else false + //! automatic scheduling of task if he isn't finished and sheduled yet + virtual bool isTaskFinished() { return true; } + + virtual void scheduleTask(TaskPtr own); + protected: + void triggerSheduler() { mScheduler->checkPendingTasks(); } + + private: + CPUSheduler* mScheduler; + }; + } +} + +#endif //__DR_UNIVERSUM_LIB_CONTROLLER_CPU_TASK_H__ + \ No newline at end of file diff --git a/src/cpp/tasks/MultithreadContainer.h b/src/cpp/tasks/MultithreadContainer.h new file mode 100644 index 000000000..60d172243 --- /dev/null +++ b/src/cpp/tasks/MultithreadContainer.h @@ -0,0 +1,54 @@ +/*/************************************************************************* +* * +* UniversumLib, collection of classes for generating and go through a * +* whole universe. It is for my Gameproject Spacecraft * +* Copyright (C) 2014, 2015, 2016, 2017 Dario Rekowski. * +* Email: ***REMOVED*** Web: ***REMOVED*** * +* * +* This program is free software: you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation, either version 3 of the License, or * +* any later version. * +* * +* This program 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. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program. If not, see . * +* * +***************************************************************************/ + +/*! + + \brief Container Wrapper class for mutex protected container + changed to poco mutex for gradido login server + + \author Dario Rekowski + + \date 08.10.2015 +*/ + +#ifndef __DR_UNIVERSUM_LIB_LIB_MULTITHREAD_CONTAINER_H__ +#define __DR_UNIVERSUM_LIB_LIB_MULTITHREAD_CONTAINER_H__ + +//#include "UniversumLib.h" +#include "Poco/Mutex.h" + +namespace UniLib { + namespace lib { + class MultithreadContainer + { + public: + + inline void lock() { mWorkMutex.lock(); } + inline void unlock() {mWorkMutex.unlock();} + protected: + private: + Poco::Mutex mWorkMutex; + }; + } +} + +#endif //__DR_UNIVERSUM_LIB_LIB_MULTITHREAD_CONTAINER_H__ \ No newline at end of file diff --git a/src/cpp/tasks/MultithreadQueue.h b/src/cpp/tasks/MultithreadQueue.h new file mode 100644 index 000000000..73c3e7d43 --- /dev/null +++ b/src/cpp/tasks/MultithreadQueue.h @@ -0,0 +1,86 @@ +/*/************************************************************************* +* * +* UniversumLib, collection of classes for generating and go through a * +* whole universe. It is for my Gameproject Spacecraft * +* Copyright (C) 2014, 2015, 2016, 2017 Dario Rekowski. * +* Email: ***REMOVED*** Web: ***REMOVED*** * +* * +* This program is free software: you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation, either version 3 of the License, or * +* any later version. * +* * +* This program 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. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program. If not, see . * +* * +***************************************************************************/ + +/*! + + \brief Container class for mutex protected queue + + \author Dario Rekowski + + \date 08.10.2015 +*/ + +#ifndef _DR_UNIVERSUM_LIB_LIB_MULTITHREAD_QUEUE_H__ +#define _DR_UNIVERSUM_LIB_LIB_MULTITHREAD_QUEUE_H__ + +#include "MultithreadContainer.h" + +namespace UniLib { + namespace lib { + template + class MultithreadQueue: protected std::queue, protected MultithreadContainer + { + public: + virtual ~MultithreadQueue() { + clear(); + } + void clear() { + lock(); + while (!std::queue::empty()) std::queue::pop(); + unlock(); + } + void push(ResourceType val) + { + lock(); + std::queue::push(val); + unlock(); + } + bool empty() + { + bool result = false; + lock(); + result = std::queue::empty(); + unlock(); + return result; + } + //! \return false if no values are there + //! \return true if value is there, gave val a copy from the value on top of queue + bool pop(ResourceType& val) + { + lock(); + if(!std::queue::empty()) { + val = std::queue::front(); + std::queue::pop(); + unlock(); + return true; + } + unlock(); + return false; + } + + + }; + + } +} + +#endif //_DR_UNIVERSUM_LIB_LIB_MULTITHREAD_QUEUE_H__ \ No newline at end of file diff --git a/src/cpp/tasks/PrepaireEmailTask.cpp b/src/cpp/tasks/PrepaireEmailTask.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/src/cpp/tasks/PrepaireEmailTask.h b/src/cpp/tasks/PrepaireEmailTask.h new file mode 100644 index 000000000..e69de29bb diff --git a/src/cpp/tasks/SendEmailTask.cpp b/src/cpp/tasks/SendEmailTask.cpp new file mode 100644 index 000000000..f4c7fcdbc --- /dev/null +++ b/src/cpp/tasks/SendEmailTask.cpp @@ -0,0 +1,16 @@ +#include "SendEmailTask.h" + +SendEmailTask::SendEmailTask() +{ + +} + +SendEmailTask::~SendEmailTask() +{ + +} + +int SendEmailTask::run() +{ + return 0; +} \ No newline at end of file diff --git a/src/cpp/tasks/SendEmailTask.h b/src/cpp/tasks/SendEmailTask.h new file mode 100644 index 000000000..6c7a628de --- /dev/null +++ b/src/cpp/tasks/SendEmailTask.h @@ -0,0 +1,21 @@ +#ifndef GRADIDO_LOGIN_SERVER_TASKS_SEND_EMAIL_TASK_INCLUDE +#define GRADIDO_LOGIN_SERVER_TASKS_SEND_EMAIL_TASK_INCLUDE + +#include "Task.h" + + +class SendEmailTask : public UniLib::controller::Task +{ +public: + SendEmailTask(); + ~SendEmailTask(); + + virtual int run(); +protected: + +private: + +}; + + +#endif //GRADIDO_LOGIN_SERVER_TASKS_SEND_EMAIL_TASK_INCLUDE \ No newline at end of file diff --git a/src/cpp/tasks/Task.cpp b/src/cpp/tasks/Task.cpp new file mode 100644 index 000000000..8daf26ef8 --- /dev/null +++ b/src/cpp/tasks/Task.cpp @@ -0,0 +1,64 @@ +#include "Task.h" + + +namespace UniLib { + namespace controller { + Task::Task() + : mTaskScheduled(false), mFinishCommand(nullptr), mParentTaskPtrArray(nullptr), + mParentTaskPtrArraySize(0), mDeleted(false), mReferenceCount(1) + { + } + + Task::Task(size_t taskPointerArraySize) + : mTaskScheduled(false), mFinishCommand(nullptr), mParentTaskPtrArray(new TaskPtr[taskPointerArraySize]), mParentTaskPtrArraySize(taskPointerArraySize), + mDeleted(false) + { + } + + Task::~Task() + { + if (mParentTaskPtrArraySize) { + delete[] mParentTaskPtrArray; + } + mParentTaskPtrArraySize = 0; + mWorkingMutex.lock(); + mDeleted = true; + mWorkingMutex.unlock(); + } + + bool Task::isAllParentsReady() + { + bool allFinished = true; + lock(); + for(size_t i = 0; i < mParentTaskPtrArraySize; i++) { + TaskPtr task = mParentTaskPtrArray[i]; + if (!task.isNull()) { + allFinished = false; + continue; + } + if(!task->isTaskFinished()) { + allFinished = false; + if(!task->isTaskSheduled()) + mParentTaskPtrArray[i]->scheduleTask(mParentTaskPtrArray[i]); + } + } + unlock(); + return allFinished; + } + + void Task::duplicate() + { + mReferenceCount++; + } + + void Task::release() + { + mReferenceCount--; + if (0 == mReferenceCount) { + delete this; + } + + } + + } +} \ No newline at end of file diff --git a/src/cpp/tasks/Task.h b/src/cpp/tasks/Task.h new file mode 100644 index 000000000..98dc0d6f2 --- /dev/null +++ b/src/cpp/tasks/Task.h @@ -0,0 +1,127 @@ +/*/************************************************************************* +* * +* UniversumLib, collection of classes for generating and go through a * +* whole universe. It is for my Gameproject Spacecraft * +* Copyright (C) 2014, 2015, 2016, 2017 Dario Rekowski. * +* Email: ***REMOVED*** Web: ***REMOVED*** * +* * +* This program is free software: you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation, either version 3 of the License, or * +* any later version. * +* * +* This program 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. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program. If not, see . * +* * +***************************************************************************/ +/*! + * + * \author: Dario Rekowski + * + * \date: 27.08.15 + * + * \desc: Task save at the same time the result of his task and the way to get to the result + */ + +#ifndef __DR_UNIVERSUM_LIB_CONTROLLER_TASK_H__ +#define __DR_UNIVERSUM_LIB_CONTROLLER_TASK_H__ + + + //#include "UniversumLib.h" + +#include "Poco/AutoPtr.h" +#include "Poco/Mutex.h" +#include + + +namespace UniLib { + namespace controller { + + + class Task; + typedef Poco::AutoPtr TaskPtr; + + class Command { + public: + virtual int taskFinished(Task* task) = 0; + }; + + + class Task + { + public: + Task(); + Task(size_t parentTaskPointerArraySize); + virtual ~Task(); + + virtual bool isReady() { return isAllParentsReady(); } + // called from scheduler + //! \brief return true if all parent task finished or return false and schedule not already finished parent tasks + bool isAllParentsReady(); + //! \brief return true if task has finished, else false + //! automatic scheduling of task if he isn't finished and sheduled yet + virtual bool isTaskFinished() { return false; } + //! \brief called from task scheduler, maybe from another thread + virtual int run() = 0; + + + + inline void lock() {mWorkingMutex.lock();} + inline void unlock() {mWorkingMutex.unlock();} + + inline void setParentTaskPtrInArray(TaskPtr task, size_t index) + { + assert(index < mParentTaskPtrArraySize); + mParentTaskPtrArray[index] = task; + } + /* inline void setParentTaskPtrInArray(DRResourcePtrHolder* resourceHolder, size_t index) { + assert(index < mParentTaskPtrArraySize); + mParentTaskPtrArray[index] = resourceHolder; + }*/ + + inline void setFinishCommand(Command* command) {mFinishCommand = command;} + + // from parent + virtual const char* getResourceType() const {return "Task";}; +#ifdef _UNI_LIB_DEBUG + virtual const char* getName() const { return mName.data(); } + __inline__ void setName(const char* name) { mName = name; } +#else + virtual const char* getName() const { return ""; } +#endif + + // type check + + virtual void scheduleTask(TaskPtr own) = 0; + + // for poco auto ptr + void duplicate(); + void release(); + protected: + // scheduling only once + inline bool isTaskSheduled() {return mTaskScheduled;} + inline void taskScheduled() {mTaskScheduled = true;} + + bool mTaskScheduled; + Command* mFinishCommand; + private: + TaskPtr* mParentTaskPtrArray; + size_t mParentTaskPtrArraySize; + Poco::Mutex mWorkingMutex; + bool mDeleted; + // for poco auto ptr + int mReferenceCount; +#ifdef _UNI_LIB_DEBUG + std::string mName; +#endif + + }; + } +} + +#endif __DR_UNIVERSUM_LIB_CONTROLLER_TASK_H__ \ No newline at end of file diff --git a/src/cpp/tasks/Thread.cpp b/src/cpp/tasks/Thread.cpp new file mode 100644 index 000000000..7898233bc --- /dev/null +++ b/src/cpp/tasks/Thread.cpp @@ -0,0 +1,95 @@ +//#include "lib/Thread.h" +//#include "UniversumLib.h" +#include "Thread.h" + +namespace UniLib { + namespace lib { + + Thread::Thread(const char* threadName/* = NULL*/, bool createInConstructor/* = true*/) + : mPocoThread(nullptr), semaphore(1), exitCalled(false) + { + if (createInConstructor) init(threadName); + } + + int Thread::init(const char* threadName) + { + semaphore.wait(); + mPocoThread = new Poco::Thread(threadName); + mPocoThread->start(*this); + return 0; + } + + Thread::~Thread() + { + if(mPocoThread) + { + //Post Exit to Thread + exitCalled = true; + semaphore.wait(); + + condSignal(); + //SDL_Delay(500); + mPocoThread->join(); + //SDL_WaitThread(thread, NULL); + //LOG_WARNING_SDL(); + delete mPocoThread; + + mPocoThread = nullptr; + } + } + + int Thread::condSignal() + { + condition.signal(); + /*if(SDL_CondSignal(condition)== -1) //LOG_ERROR_SDL(DR_ERROR); + { + LOG_WARNING("Fehler beim Aufruf von SDL_CondSignal"); + LOG_ERROR_SDL(DR_ERROR); + }*/ + return 0; + } + + void Thread::run() + { + //Thread* t = this; + while (true) { + try { + semaphore.tryWait(100); + printf("[Thread::%s] end worker thread\n", __FUNCTION__); + break; + } catch (Poco::TimeoutException& e) { + + if (exitCalled) return; + // Lock work mutex + threadLock(); + //int status = SDL_CondWait(t->condition, t->mutex); + try { + condition.wait(mutex); + if (exitCalled) return; + int ret = ThreadFunction(); + threadUnlock(); + if (ret) + { + //EngineLog.writeToLog("error-code: %d", ret); + printf("[Thread::%s] error running thread functon: %d, exit thread\n", __FUNCTION__, ret); + return; + } + } + catch (Poco::Exception& e) { + //unlock mutex and exit + threadUnlock(); + //LOG_ERROR("Fehler in Thread, exit", -1); + printf("[Thread::%s] exception: %s\n", __FUNCTION__, e.message().data()); + return; + } + + } + catch (Poco::Exception& e) { + printf("[Thread::%s] exception: %s\n", __FUNCTION__, e.message().data()); + return; + } + } + + } + } +} \ No newline at end of file diff --git a/src/cpp/tasks/Thread.h b/src/cpp/tasks/Thread.h new file mode 100644 index 000000000..3f7fdba5b --- /dev/null +++ b/src/cpp/tasks/Thread.h @@ -0,0 +1,80 @@ +/*/************************************************************************* +* * +* UniversumLib, collection of classes for generating and go through a * +* whole universe. It is for my Gameproject Spacecraft * +* Copyright (C) 2014, 2015, 2016, 2017 Dario Rekowski. * +* Email: ***REMOVED*** Web: ***REMOVED*** * +* * +* This program is free software: you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation, either version 3 of the License, or * +* any later version. * +* * +* This program 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. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program. If not, see . * +* * +***************************************************************************/ + +/** + * @Author Dario Rekowski + * + * @Date 13.08.12 + * + * @Desc Class for easy handling threading + */ + +#ifndef __DR_UNIVERSUM_LIB_THREAD__ +#define __DR_UNIVERSUM_LIB_THREAD__ + +//#include "Timer.h" +//#include +#include "Poco/Thread.h" +#include "Poco/Mutex.h" +#include "Poco/Semaphore.h" +#include "Poco/Condition.h" + +namespace UniLib { + namespace lib { + class Thread : public Poco::Runnable + { + public: + //! \param threadName used since SDL 1.3, for BeOS max. 32, for Linux max 16, for Visual Studio 6.0 max 9 char + //! \param createInConstructor set to false if thread shouldn't create in constructor, for example if SDL isn't loaded yet + Thread(const char* threadName = NULL, bool createInConstructor = true); + virtual ~Thread(); + + inline void threadLock() {mutex.lock();} + inline void threadUnlock() {mutex.unlock();} + // signal data chance, will continue thread, if he is paused + int condSignal(); + + //! \param threadName used since SDL 1.3, for BeOS max. 32, for Linux max 16, for Visual Studio 6.0 max 9 char + int init(const char* threadName); + + void run(); + protected: + //! \brief will be called every time from thread, when condSignal was called + //! will be called from thread with locked working mutex,
+ //! mutex will be unlock after calling this function + //! \return if return isn't 0, thread will exit + virtual int ThreadFunction() = 0; + + + + Poco::Mutex mutex; + Poco::Thread* mPocoThread; + Poco::Condition condition; + Poco::Semaphore semaphore; + bool exitCalled; + }; + + } +} + + +#endif //__DR_UNIVERSUM_LIB_THREAD__ diff --git a/src/cpp/tasks/WriteIntoDBTask.cpp b/src/cpp/tasks/WriteIntoDBTask.cpp new file mode 100644 index 000000000..62a13595d --- /dev/null +++ b/src/cpp/tasks/WriteIntoDBTask.cpp @@ -0,0 +1,16 @@ +#include "WriteIntoDBTask.h" + +WriteIntoDBTask::WriteIntoDBTask() +{ + +} + +WriteIntoDBTask::~WriteIntoDBTask() +{ + +} + +int WriteIntoDBTask::run() +{ + return 0; +} \ No newline at end of file diff --git a/src/cpp/tasks/WriteIntoDBTask.h b/src/cpp/tasks/WriteIntoDBTask.h new file mode 100644 index 000000000..63fcc77a8 --- /dev/null +++ b/src/cpp/tasks/WriteIntoDBTask.h @@ -0,0 +1,21 @@ +#ifndef GRADIDO_LOGIN_SERVER_TASKS_WRITE_INTO_DB_TASK_INCLUDE +#define GRADIDO_LOGIN_SERVER_TASKS_WRITE_INTO_DB_TASK_INCLUDE + +#include "Task.h" + + +class WriteIntoDBTask : public UniLib::controller::Task +{ +public: + WriteIntoDBTask(); + ~WriteIntoDBTask(); + + virtual int run(); +protected: + +private: + +}; + + +#endif //GRADIDO_LOGIN_SERVER_TASKS_WRITE_INTO_DB_TASK_INCLUDE \ No newline at end of file diff --git a/src/cpsp/dashboard.cpsp b/src/cpsp/dashboard.cpsp new file mode 100644 index 000000000..6ce441fa8 --- /dev/null +++ b/src/cpsp/dashboard.cpsp @@ -0,0 +1,25 @@ +<%@ page class="DashboardPage" %> +<%@ page compressed="true" %> +<%! +#include "../SingletonManager/SessionManager.h" +%> +<% + Poco::Net::NameValueCollection cookies; + request.getCookies(cookies); +%> + + + + + +Gradido Login Server: Dashboard + + + + +
+

Willkommen <%= mSession->getUser()->getName() %>

+ +
+ + diff --git a/src/cpsp/emailOptIn.cpsp b/src/cpsp/emailOptIn.cpsp new file mode 100644 index 000000000..802014acb --- /dev/null +++ b/src/cpsp/emailOptIn.cpsp @@ -0,0 +1,93 @@ +<%@ page class="EmailOptInPage" %> +<%@ page form="true" %> +<%@ page compressed="true" %> +<%! +#include "../SingletonManager/SessionManager.h" +#include "Poco/Net/HTTPCookie.h" +%> +<%% + auto session = SessionManager::getInstance()->getNewSession(); + bool userReturned = false; + if(!form.empty()) { + userReturned = session->createUser( + form.get("register-name"), + form.get("register-email"), + form.get("register-password") + ); + if(userReturned) { + auto cookie_id = session->getHandle(); + auto user_host = request.clientAddress().toString(); + printf("cookie: %d, user_host: %s\n", cookie_id, user_host.data()); + response.addCookie(Poco::Net::HTTPCookie("user", std::to_string(cookie_id))); + } + } +%> + + + + + +Gradido Login Server: Email OptIn + + + + + +
+

Einen neuen Account anlegen

+ <% if(!form.empty() && userReturned) {%> +
+
+ Schreibe dir den Merkspruch auf und packe ihn gut weg. Du brauchst ihn um deine Adresse wiederherzustellen. Wenn du ihn verlierst, sind auch deine Gradidos verloren. +
+
+ <%= session->getPassphrase() %> +
+
+ <% } else { %> +
+ + <% if(!form.empty() && !userReturned) {%> + <%= session->getErrorsHtml() %> + <%} %> +
+ Account anlegen +

Bitte gebe deine Daten um einen Account anzulegen

+

+ + "/> +

+

+ + "/> +

+

+ + +

+

Hast du schonmal ein Gradido Konto besessen?

+

+ + +

+

+ + +

+ +
+ + +
+ <% } %> +
+ +