-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: jparisu <[email protected]>
- Loading branch information
jparisu
committed
Dec 1, 2022
1 parent
dd327d3
commit f6f7ddf
Showing
36 changed files
with
2,577 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
cpp_utils/include/cpp_utils/threading/connector/OneShotConnector.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima). | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
/** | ||
* @file OwnedTask.hpp | ||
* | ||
* This file contains class Task definition. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <functional> | ||
|
||
#include <cpp_utils/threading/task/ITask.hpp> | ||
#include <cpp_utils/threading/manager/IManager.hpp> | ||
|
||
namespace eprosima { | ||
namespace utils { | ||
namespace threading { | ||
|
||
template <typename ... Args> | ||
class OneShotConnector | ||
{ | ||
public: | ||
|
||
static void execute(IManager* tp, const std::function<void(Args...)>& callback, Args... args); | ||
|
||
static void execute(IManager* tp, std::function<void(Args...)>&& callback, Args... args); | ||
|
||
}; | ||
using SimpleOneShotConnector = OneShotConnector<>; | ||
|
||
} /* namespace threading */ | ||
} /* namespace utils */ | ||
} /* namespace eprosima */ | ||
|
||
// Include implementation template file | ||
#include <cpp_utils/threading/connector/impl/OneShotConnector.ipp> |
63 changes: 63 additions & 0 deletions
63
cpp_utils/include/cpp_utils/threading/connector/SlotConnector.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima). | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
/** | ||
* @file SlotConnector.hpp | ||
* | ||
* This file contains class SlotConnector definition. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <functional> | ||
|
||
#include <cpp_utils/threading/task/ITask.hpp> | ||
#include <cpp_utils/threading/manager/IManager.hpp> | ||
|
||
namespace eprosima { | ||
namespace utils { | ||
namespace threading { | ||
|
||
template <typename ... Args> | ||
class SlotConnector | ||
{ | ||
public: | ||
|
||
SlotConnector( | ||
IManager* manager, | ||
const std::function<void(Args...)>& callback); | ||
|
||
SlotConnector( | ||
IManager* manager, | ||
std::function<void(Args...)>&& callback); | ||
|
||
~SlotConnector() = default; | ||
|
||
void execute(Args...); | ||
|
||
protected: | ||
|
||
IManager* manager_; | ||
|
||
std::function<void (Args...)> callback_; | ||
|
||
}; | ||
using SimpleSlotConnector = SlotConnector<>; | ||
|
||
} /* namespace threading */ | ||
} /* namespace utils */ | ||
} /* namespace eprosima */ | ||
|
||
// Include implementation template file | ||
#include <cpp_utils/threading/connector/impl/SlotConnector.ipp> |
73 changes: 73 additions & 0 deletions
73
cpp_utils/include/cpp_utils/threading/connector/impl/OneShotConnector.ipp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima). | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
/** | ||
* @file OneShotConnector.hpp | ||
* | ||
* This file contains class OneShotConnector implementation. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <cpp_utils/threading/task/ArgsOwnedTask.hpp> | ||
|
||
namespace eprosima { | ||
namespace utils { | ||
namespace threading { | ||
|
||
template <typename ... Args> | ||
void OneShotConnector<Args...>::execute( | ||
IManager* manager, | ||
const std::function<void(Args...)>& callback, | ||
Args... args) | ||
{ | ||
manager->execute( | ||
std::make_unique<ArgsOwnedTask<Args...>>( | ||
callback, | ||
args... | ||
) | ||
); | ||
} | ||
|
||
template <typename ... Args> | ||
void OneShotConnector<Args...>::execute( | ||
IManager* manager, | ||
std::function<void(Args...)>&& callback, | ||
Args... args) | ||
{ | ||
manager->execute( | ||
std::make_unique<ArgsOwnedTask<Args...>>( | ||
std::move(callback), | ||
args... | ||
) | ||
); | ||
} | ||
|
||
// template <typename ... Args> | ||
// void OneShotConnector<Args...>::execute( | ||
// IManager* manager, | ||
// std::function<void(Args...)> callback, | ||
// Args... args) | ||
// { | ||
// manager->execute( | ||
// std::make_unique<ArgsOwnedTask<Args...>>( | ||
// callback, | ||
// args... | ||
// ) | ||
// ); | ||
// } | ||
|
||
} /* namespace thread */ | ||
} /* namespace event */ | ||
} /* namespace eprosima */ |
60 changes: 60 additions & 0 deletions
60
cpp_utils/include/cpp_utils/threading/connector/impl/SlotConnector.ipp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima). | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
/** | ||
* @file SlotConnector.hpp | ||
* | ||
* This file contains class SlotConnector implementation. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <cpp_utils/threading/task/ArgsOwnedTask.hpp> | ||
|
||
namespace eprosima { | ||
namespace utils { | ||
namespace threading { | ||
|
||
template <typename ... Args> | ||
SlotConnector<Args...>::SlotConnector( | ||
IManager* manager, | ||
const std::function<void(Args...)>& callback) | ||
: manager_(manager) | ||
, callback_(callback) | ||
{ | ||
} | ||
|
||
template <typename ... Args> | ||
SlotConnector<Args...>::SlotConnector( | ||
IManager* manager, | ||
std::function<void(Args...)>&& callback) | ||
: manager_(manager) | ||
, callback_(std::move(callback)) | ||
{ | ||
} | ||
|
||
template <typename ... Args> | ||
void SlotConnector<Args...>::execute(Args... args) | ||
{ | ||
manager_->execute( | ||
std::make_unique<ArgsOwnedTask<Args...>>( | ||
callback_, | ||
args... | ||
) | ||
); | ||
} | ||
|
||
} /* namespace thread */ | ||
} /* namespace event */ | ||
} /* namespace eprosima */ |
66 changes: 66 additions & 0 deletions
66
cpp_utils/include/cpp_utils/threading/manager/AsyncManager.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima). | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
/** | ||
* @file AsyncManager.hpp | ||
* | ||
* This file contains class AsyncManager definition. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <map> | ||
#include <mutex> | ||
#include <thread> | ||
#include <vector> | ||
|
||
#include <cpp_utils/library/library_dll.h> | ||
#include <cpp_utils/threading/manager/IManager.hpp> | ||
#include <cpp_utils/threading/thread/CustomThread.hpp> | ||
#include <cpp_utils/types/Atomicable.hpp> | ||
|
||
namespace eprosima { | ||
namespace utils { | ||
namespace threading { | ||
|
||
using TasksCollectionType = | ||
Atomicable< | ||
std::vector< | ||
std::pair< | ||
std::unique_ptr<CustomThread>, | ||
std::unique_ptr<ITask>>>>; | ||
|
||
/** | ||
* TODO | ||
*/ | ||
class AsyncManager : public IManager | ||
{ | ||
public: | ||
|
||
AsyncManager() = default; | ||
|
||
~AsyncManager(); | ||
|
||
virtual void execute(std::unique_ptr<ITask>&& task) override; | ||
|
||
void clean_threads(); | ||
|
||
protected: | ||
|
||
TasksCollectionType tasks_running_; | ||
}; | ||
|
||
} /* namespace threading */ | ||
} /* namespace utils */ | ||
} /* namespace eprosima */ |
38 changes: 38 additions & 0 deletions
38
cpp_utils/include/cpp_utils/threading/manager/IManager.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima). | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
/** | ||
* @file IManager.hpp | ||
* | ||
* This file contains class SlotThreadPool definition. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <cpp_utils/threading/task/ITask.hpp> | ||
|
||
namespace eprosima { | ||
namespace utils { | ||
namespace threading { | ||
|
||
class IManager | ||
{ | ||
public: | ||
virtual ~IManager() {}; | ||
virtual void execute(std::unique_ptr<ITask>&& task) = 0; | ||
}; | ||
|
||
} /* namespace threading */ | ||
} /* namespace utils */ | ||
} /* namespace eprosima */ |
Oops, something went wrong.