-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TgBot++: Make sighandlers registerable, add sighandler to builder
- Add galaxy s4 config
- Loading branch information
Showing
17 changed files
with
138 additions
and
43 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
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
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
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
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
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Name RomName LocalManifestUrl LocalManifestBranch device variant | ||
EvoxTablet Evox https://github.com/Roynas-Android-Playground/local_manifests/ tb128fu-Evolution-X-udc tb128fu user | ||
EvoxA30 Evox https://github.com/Roynas-Android-Playground/local_manifests/ Exynos7885-fourteen a30 user | ||
EvoxA30 Evox https://github.com/Roynas-Android-Playground/local_manifests/ Exynos7885-fourteen a30 user | ||
crDroidS4 crDroid https://github.com/Roynas-Android-Playground/local_manifests/ ks01lteskt-crDroid-11.0 ks01ltexx user |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
# Name RepoUrl RepoBranch TargetName OutZipPrefix | ||
Evox https://github.com/Evolution-XYZ/manifest udc evolution EvolutionX | ||
crDroid https://github.com/crdroidandroid/android/ 11.0 bacon crDroidAndroid |
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
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,14 @@ | ||
import os | ||
|
||
def custom_print(*args, **kwargs): | ||
logfd = int(os.environ['PYTHON_LOG_FD']) | ||
|
||
# Get kwargs or set default values | ||
sep = kwargs.get('sep', ' ') | ||
end = kwargs.get('end', '\n') | ||
|
||
# Construct the message | ||
message = sep.join(map(str, args)) + end | ||
|
||
# Write the message to the file descriptor | ||
os.write(logfd, message.encode()) |
This file was deleted.
Oops, something went wrong.
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
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
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
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,65 @@ | ||
#include <functional> | ||
#include <map> | ||
|
||
#include "InstanceClassBase.hpp" | ||
|
||
struct OnTerminateRegistrar : InstanceClassBase<OnTerminateRegistrar> { | ||
using callback_type = std::function<void(int sig)>; | ||
|
||
/** | ||
* @brief Registers a callback function to be called when the process | ||
* terminates. | ||
* | ||
* @param callback The function to be called when signal is received. | ||
*/ | ||
void registerCallback(const callback_type& callback) { | ||
callbacks.emplace_back(callback); | ||
} | ||
|
||
/** | ||
* @brief Registers a callback function with a token to be called the | ||
* process terminates. | ||
* | ||
* @param callback The function to be called when signal is received. | ||
* @param token A unique identifier for the callback. | ||
*/ | ||
void registerCallback(const callback_type& callback, const size_t token) { | ||
callbacksWithToken[token] = callback; | ||
} | ||
|
||
/** | ||
* @brief Unregisters a callback function with a token from the list of | ||
* callbacks to be called when any message is received. | ||
* | ||
* @param token The unique identifier of the callback to be unregistered. | ||
* | ||
* @return True if the callback with the specified token was found and | ||
* successfully unregistered, false otherwise. | ||
*/ | ||
bool unregisterCallback(const size_t token) { | ||
auto it = callbacksWithToken.find(token); | ||
if (it == callbacksWithToken.end()) { | ||
return false; | ||
} | ||
callbacksWithToken.erase(it); | ||
return true; | ||
} | ||
|
||
/** | ||
* @brief Calls all registered callback functions with the given signal. | ||
* | ||
* @param sig The signal to be sent to all registered callback functions. | ||
*/ | ||
void callCallbacks(int sig) { | ||
for (const auto& callback : callbacks) { | ||
callback(sig); | ||
} | ||
for (const auto& pair : callbacksWithToken) { | ||
pair.second(sig); | ||
} | ||
} | ||
|
||
private: | ||
std::vector<callback_type> callbacks; | ||
std::map<size_t, callback_type> callbacksWithToken; | ||
}; |
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
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 |
---|---|---|
@@ -1,18 +1,22 @@ | ||
#include <absl/log/log.h> | ||
|
||
#include <ManagedThreads.hpp> | ||
#include <database/bot/TgBotDatabaseImpl.hpp> | ||
#include <mutex> | ||
|
||
#include "InstanceClassBase.hpp" | ||
#include "OnTerminateRegistrar.hpp" | ||
#include "libsighandler.h" | ||
|
||
void defaultSignalHandler(int s) { | ||
static std::once_flag once; | ||
std::call_once(once, [s] { defaultCleanupFunction(); }); | ||
std::call_once(once, [s] { defaultCleanupFunction(s); }); | ||
std::exit(0); | ||
}; | ||
|
||
void defaultCleanupFunction() { | ||
void defaultCleanupFunction(int bySignal) { | ||
LOG(INFO) << "Exiting"; | ||
ThreadManager::getInstance()->destroyManager(); | ||
TgBotDatabaseImpl::getInstance()->unloadDatabase(); | ||
OnTerminateRegistrar::getInstance()->callCallbacks(bySignal); | ||
LOG(INFO) << "TgBot process exiting, Goodbye!"; | ||
} | ||
} | ||
|
||
DECLARE_CLASS_INST(OnTerminateRegistrar); |
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