#include <utility>
#include "tizen-core/log_private.h"
+#include "tizen-core/task.h"
namespace tizen_core {
namespace {
Source* Find(GSource* gsource) {
std::lock_guard<std::recursive_mutex> lock(mutex_);
auto found = map_.find(gsource);
- if (found == map_.end())
- return nullptr;
+ if (found == map_.end()) return nullptr;
return found->second;
}
Source::Source(GSource* handle) : handle_(handle) {}
Source::Source() {
- static GSourceFuncs source_funcs = {
- .prepare = SourcePrepareFunc,
- .check = SourceCheckFunc,
- .dispatch = SourceDispatchFunc,
- .finalize = SourceFinalizeFunc,
- .closure_callback = nullptr,
- .closure_marshal = nullptr
- };
+ static GSourceFuncs source_funcs = {.prepare = SourcePrepareFunc,
+ .check = SourceCheckFunc,
+ .dispatch = SourceDispatchFunc,
+ .finalize = SourceFinalizeFunc,
+ .closure_callback = nullptr,
+ .closure_marshal = nullptr};
handle_ = g_source_new(&source_funcs, sizeof(GSource));
if (handle_ == nullptr) {
- _E("g_source_new() is failed"); // LCOV_EXCL_LINE
+ _E("g_source_new() is failed"); // LCOV_EXCL_LINE
throw std::runtime_error("g_source_new() is failed"); // LCOV_EXCL_LINE
}
source_manager.Insert(this);
[=](const std::shared_ptr<PollFd>& pollfd) { return pollfd == poll_fd; });
}
-void Source::Attach(const std::shared_ptr<Context>& context) {
- if (handle_ == nullptr)
- return;
+void Source::Attach(const std::shared_ptr<Context>& context, Task* task) {
+ if (handle_ == nullptr) return;
- if (attached_)
- return;
+ if (attached_) return;
+ task_ = task;
g_source_attach(handle_, context->GetHandle());
g_source_unref(handle_);
attached_ = true;
}
+Task* Source::GetTask() {
+ return task_;
+}
+
bool Source::IsDisposing() const { return disposing_; }
void Source::Dispose() { disposing_ = true; }
std::recursive_mutex& Source::GetMutex() const { return mutex_; }
// LCOV_EXCL_START
-bool Source::OnSourcePrepare(int* timeout) {return false; }
+bool Source::OnSourcePrepare(int* timeout) { return false; }
bool Source::OnSourceCheck() { return false; }
gboolean Source::SourcePrepareFunc(GSource* gsource, gint* timeout) {
auto source = source_manager.Find(gsource);
- if (source == nullptr)
- return FALSE;
+ if (source == nullptr) return FALSE;
std::lock_guard<std::recursive_mutex> lock(source->GetMutex());
if (source->IsDisposing()) return FALSE;
gboolean Source::SourceCheckFunc(GSource* gsource) {
auto source = source_manager.Find(gsource);
- if (source == nullptr)
- return FALSE;
+ if (source == nullptr) return FALSE;
std::lock_guard<std::recursive_mutex> lock(source->GetMutex());
if (source->IsDisposing()) return FALSE;
gboolean Source::SourceDispatchFunc(GSource* gsource, GSourceFunc callback,
gpointer user_data) {
auto source = source_manager.Find(gsource);
- if (source == nullptr)
- return FALSE;
+ if (source == nullptr) return FALSE;
std::lock_guard<std::recursive_mutex> lock(source->GetMutex());
if (source->IsDisposing()) return FALSE;
void Source::SourceFinalizeFunc(GSource* gsource) {
auto source = source_manager.Find(gsource);
- if (source == nullptr)
- return;
+ if (source == nullptr) return;
std::lock_guard<std::recursive_mutex> lock(source->GetMutex());
source->OnSourceFinalize();
void AddPoll(std::shared_ptr<PollFd> poll_fd) override;
void RemovePoll(const std::shared_ptr<PollFd>& poll_fd) override;
- void Attach(const std::shared_ptr<Context>& context) override;
+ void Attach(const std::shared_ptr<Context>& context,
+ tizen_core::Task* task) override;
bool IsAttached() const;
bool IsDisposing() const override;
void Dispose() override;
GSource* GetHandle() const;
void SetPriority(int priority);
+ Task* GetTask();
virtual bool OnSourcePrepare(int* timeout);
virtual bool OnSourceCheck();
bool attached_ = false;
std::list<std::shared_ptr<PollFd>> poll_fds_;
mutable std::recursive_mutex mutex_;
+ Task* task_ = nullptr;
};
} // namespace tizen_core