mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
adding task logic from Universum Game Engine
This commit is contained in:
parent
f7744ee2c1
commit
3d3deae9c7
76
src/cpp/tasks/CPUSheduler.cpp
Normal file
76
src/cpp/tasks/CPUSheduler.cpp
Normal file
@ -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<TaskPtr>::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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
91
src/cpp/tasks/CPUSheduler.h
Normal file
91
src/cpp/tasks/CPUSheduler.h
Normal file
@ -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 <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
*
|
||||||
|
* \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 <string>
|
||||||
|
#include <list>
|
||||||
|
#include <queue>
|
||||||
|
|
||||||
|
#include "Poco/AutoPtr.h"
|
||||||
|
|
||||||
|
#include "MultithreadQueue.h"
|
||||||
|
|
||||||
|
namespace UniLib {
|
||||||
|
namespace controller {
|
||||||
|
|
||||||
|
class Task;
|
||||||
|
typedef Poco::AutoPtr<Task> 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<CPUShedulerThread*> mFreeWorkerThreads;
|
||||||
|
// work to do
|
||||||
|
//lib::MultithreadQueue<TaskPtr> mPendingTasks;
|
||||||
|
std::list<TaskPtr> mPendingTasks;
|
||||||
|
lib::MultithreadContainer mPendingTasksMutex;
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //__DR_UNIVERSUM_LIB_CONTROLLER_CPU_SHEDULER_H__
|
||||||
|
|
||||||
57
src/cpp/tasks/CPUShedulerThread.cpp
Normal file
57
src/cpp/tasks/CPUShedulerThread.cpp
Normal file
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
78
src/cpp/tasks/CPUShedulerThread.h
Normal file
78
src/cpp/tasks/CPUShedulerThread.h
Normal file
@ -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 <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
*
|
||||||
|
* \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<Task> 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,<br>
|
||||||
|
//! 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__
|
||||||
|
|
||||||
32
src/cpp/tasks/CPUTask.cpp
Normal file
32
src/cpp/tasks/CPUTask.cpp
Normal file
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
71
src/cpp/tasks/CPUTask.h
Normal file
71
src/cpp/tasks/CPUTask.h
Normal file
@ -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 <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
*
|
||||||
|
* \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<CPUTask> 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__
|
||||||
|
|
||||||
54
src/cpp/tasks/MultithreadContainer.h
Normal file
54
src/cpp/tasks/MultithreadContainer.h
Normal file
@ -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 <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
|
||||||
|
\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__
|
||||||
86
src/cpp/tasks/MultithreadQueue.h
Normal file
86
src/cpp/tasks/MultithreadQueue.h
Normal file
@ -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 <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
|
||||||
|
\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 ResourceType>
|
||||||
|
class MultithreadQueue: protected std::queue<ResourceType>, protected MultithreadContainer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~MultithreadQueue() {
|
||||||
|
clear();
|
||||||
|
}
|
||||||
|
void clear() {
|
||||||
|
lock();
|
||||||
|
while (!std::queue<ResourceType>::empty()) std::queue<ResourceType>::pop();
|
||||||
|
unlock();
|
||||||
|
}
|
||||||
|
void push(ResourceType val)
|
||||||
|
{
|
||||||
|
lock();
|
||||||
|
std::queue<ResourceType>::push(val);
|
||||||
|
unlock();
|
||||||
|
}
|
||||||
|
bool empty()
|
||||||
|
{
|
||||||
|
bool result = false;
|
||||||
|
lock();
|
||||||
|
result = std::queue<ResourceType>::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<ResourceType>::empty()) {
|
||||||
|
val = std::queue<ResourceType>::front();
|
||||||
|
std::queue<ResourceType>::pop();
|
||||||
|
unlock();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
unlock();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //_DR_UNIVERSUM_LIB_LIB_MULTITHREAD_QUEUE_H__
|
||||||
0
src/cpp/tasks/PrepaireEmailTask.cpp
Normal file
0
src/cpp/tasks/PrepaireEmailTask.cpp
Normal file
0
src/cpp/tasks/PrepaireEmailTask.h
Normal file
0
src/cpp/tasks/PrepaireEmailTask.h
Normal file
16
src/cpp/tasks/SendEmailTask.cpp
Normal file
16
src/cpp/tasks/SendEmailTask.cpp
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#include "SendEmailTask.h"
|
||||||
|
|
||||||
|
SendEmailTask::SendEmailTask()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
SendEmailTask::~SendEmailTask()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int SendEmailTask::run()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
21
src/cpp/tasks/SendEmailTask.h
Normal file
21
src/cpp/tasks/SendEmailTask.h
Normal file
@ -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
|
||||||
64
src/cpp/tasks/Task.cpp
Normal file
64
src/cpp/tasks/Task.cpp
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
127
src/cpp/tasks/Task.h
Normal file
127
src/cpp/tasks/Task.h
Normal file
@ -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 <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
***************************************************************************/
|
||||||
|
/*!
|
||||||
|
*
|
||||||
|
* \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 <assert.h>
|
||||||
|
|
||||||
|
|
||||||
|
namespace UniLib {
|
||||||
|
namespace controller {
|
||||||
|
|
||||||
|
|
||||||
|
class Task;
|
||||||
|
typedef Poco::AutoPtr<Task> 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__
|
||||||
95
src/cpp/tasks/Thread.cpp
Normal file
95
src/cpp/tasks/Thread.cpp
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
80
src/cpp/tasks/Thread.h
Normal file
80
src/cpp/tasks/Thread.h
Normal file
@ -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 <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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 <sdl/SDL_thread.h>
|
||||||
|
#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,<br>
|
||||||
|
//! 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__
|
||||||
16
src/cpp/tasks/WriteIntoDBTask.cpp
Normal file
16
src/cpp/tasks/WriteIntoDBTask.cpp
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#include "WriteIntoDBTask.h"
|
||||||
|
|
||||||
|
WriteIntoDBTask::WriteIntoDBTask()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
WriteIntoDBTask::~WriteIntoDBTask()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int WriteIntoDBTask::run()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
21
src/cpp/tasks/WriteIntoDBTask.h
Normal file
21
src/cpp/tasks/WriteIntoDBTask.h
Normal file
@ -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
|
||||||
25
src/cpsp/dashboard.cpsp
Normal file
25
src/cpsp/dashboard.cpsp
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<%@ page class="DashboardPage" %>
|
||||||
|
<%@ page compressed="true" %>
|
||||||
|
<%!
|
||||||
|
#include "../SingletonManager/SessionManager.h"
|
||||||
|
%>
|
||||||
|
<%
|
||||||
|
Poco::Net::NameValueCollection cookies;
|
||||||
|
request.getCookies(cookies);
|
||||||
|
%>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Gradido Login Server: Dashboard</title>
|
||||||
|
<!--<link rel="stylesheet" type="text/css" href="css/styles.min.css">-->
|
||||||
|
<link rel="stylesheet" type="text/css" href="https://gradido2.dario-rekowski.de/css/styles.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="grd_container">
|
||||||
|
<h1>Willkommen <%= mSession->getUser()->getName() %></h1>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
93
src/cpsp/emailOptIn.cpsp
Normal file
93
src/cpsp/emailOptIn.cpsp
Normal file
@ -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)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
%>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Gradido Login Server: Email OptIn</title>
|
||||||
|
<!--<link rel="stylesheet" type="text/css" href="css/styles.min.css">-->
|
||||||
|
<link rel="stylesheet" type="text/css" href="https://gradido2.dario-rekowski.de/css/styles.css">
|
||||||
|
<style type="text/css" >
|
||||||
|
input:not([type='radio']) {
|
||||||
|
width:200px;
|
||||||
|
}
|
||||||
|
label:not(.grd_radio_label) {
|
||||||
|
width:80px;
|
||||||
|
display:inline-block;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="grd_container">
|
||||||
|
<h1>Einen neuen Account anlegen</h1>
|
||||||
|
<% if(!form.empty() && userReturned) {%>
|
||||||
|
<div class="grd_text-max-width">
|
||||||
|
<div class="grd_text">
|
||||||
|
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.
|
||||||
|
</div>
|
||||||
|
<div class="grd_textarea">
|
||||||
|
<%= session->getPassphrase() %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% } else { %>
|
||||||
|
<form method="POST">
|
||||||
|
|
||||||
|
<% if(!form.empty() && !userReturned) {%>
|
||||||
|
<%= session->getErrorsHtml() %>
|
||||||
|
<%} %>
|
||||||
|
<fieldset class="grd_container_small">
|
||||||
|
<legend>Account anlegen</legend>
|
||||||
|
<p>Bitte gebe deine Daten um einen Account anzulegen</p>
|
||||||
|
<p class="grd_small">
|
||||||
|
<label for="register-name">Vorname</label>
|
||||||
|
<input id="register-name" type="text" name="register-name" value="<%= !form.empty() ? form.get("register-name") : "" %>"/>
|
||||||
|
</p>
|
||||||
|
<p class="grd_small">
|
||||||
|
<label for="register-email">E-Mail</label>
|
||||||
|
<input id="register-email" type="email" name="register-email" value="<%= !form.empty() ? form.get("register-email") : "" %>"/>
|
||||||
|
</p>
|
||||||
|
<p class="grd_small">
|
||||||
|
<label for="register-password">Passwort</label>
|
||||||
|
<input id="register-password" type="password" name="register-password"/>
|
||||||
|
</p>
|
||||||
|
<p>Hast du schonmal ein Gradido Konto besessen?</p>
|
||||||
|
<p class="grd_small">
|
||||||
|
<input id="register-key-new-yes" type="radio" name="register-key" value="yes" checked/>
|
||||||
|
<label class="grd_radio_label" for="register-key-new-yes">Nein, bitte ein neues erstellen!</label>
|
||||||
|
</p>
|
||||||
|
<p class="grd_small">
|
||||||
|
<input id="register-key-new-no" type="radio" name="register-key" value="no"/>
|
||||||
|
<label class="grd_radio_label" for="register-key-new-no">Ja, bitte wiederherstellen!</label>
|
||||||
|
</p>
|
||||||
|
<textarea style="width:100%;height:100px" name="register-key-existing"><%= !form.empty() ? form.get("register-key-existing") : "" %></textarea>
|
||||||
|
</fieldset>
|
||||||
|
<input class="grd_bn_succeed" type="submit" name="submit" value="Anmelden">
|
||||||
|
|
||||||
|
</form>
|
||||||
|
<% } %>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Loading…
x
Reference in New Issue
Block a user