diff --git a/modules/globebrowsing/other/concurrentjobmanager.h b/modules/globebrowsing/other/concurrentjobmanager.h new file mode 100644 index 0000000000..fcfab34568 --- /dev/null +++ b/modules/globebrowsing/other/concurrentjobmanager.h @@ -0,0 +1,113 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2016 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#ifndef __CONCURRENT_JOB_MANAGER_H__ +#define __CONCURRENT_JOB_MANAGER_H__ + +#include +#include +#include +#include +#include + + + + + +namespace openspace { + + + // Templated abstract base class representing a job to be done. + // Client code derive from this class and implement the virtual execute() method + template + struct Job { + + Job() { } + virtual ~Job() { } + + virtual void execute() = 0; + virtual P product() = 0; + + /* + enum Status { + UNKNOWN, + QUEUED, + IN_PROGRESS, + FINISHED + }; + + Status status; + */ + + }; + + + + + // Templated + template + class ConcurrentJobManager{ + public: + ConcurrentJobManager() { + + } + + ~ConcurrentJobManager() { + + } + + + + void enqueueFutureJob(std::unique_ptr> job) { + dummy = std::move(job); + } + + void startInSeparateThread() { + // create new thread + dummy->execute(); + } + + std::unique_ptr> popFinishedJob() { + return std::move(dummy); + } + + + + private: + + void workerThreadMainTask() { + + } + + std::unique_ptr> dummy; + + }; + + +} // namespace openspace + + +#include + +#endif // __CONCURRENT_JOB_MANAGER_H__ diff --git a/tests/main.cpp b/tests/main.cpp index 95e1200112..054724dbcd 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -42,7 +42,9 @@ //#include //#include //#include -#include +//#include + +#include #include #include diff --git a/tests/test_concurrentjobmanager.inl b/tests/test_concurrentjobmanager.inl new file mode 100644 index 0000000000..8628307fe5 --- /dev/null +++ b/tests/test_concurrentjobmanager.inl @@ -0,0 +1,70 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2016 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#include "gtest/gtest.h" + +#include + +#define _USE_MATH_DEFINES +#include +#include + + + + +class ConcurrentJobManagerTest : public testing::Test {}; + + +using namespace openspace; + + +struct TestJob : public Job { + virtual void execute() { + std::cout << "executing l33t job" << std::endl; + prod = 1337; + } + + virtual int product() { + return prod; + } + + int prod; +}; + + +TEST_F(ConcurrentJobManagerTest, Basic) { + ConcurrentJobManager jobManager; + std::unique_ptr testJob = std::unique_ptr(new TestJob()); + + jobManager.enqueueFutureJob(std::move(testJob)); + jobManager.startInSeparateThread(); + + using namespace std::chrono_literals; + std::this_thread::sleep_for(2s); + + auto finishedJob = jobManager.popFinishedJob(); + + int product = finishedJob->product(); + std::cout << "product is " << product << std::endl; +} \ No newline at end of file