#define __TIZEN_BASE_TIZEN_CORE_H__
#include <stdbool.h>
+#include <stdint.h>
#include <tizen_error.h>
+#include <poll.h>
#include <tizen_core_channel.h>
#include <tizen_core_event.h>
*/
typedef void *tizen_core_source_h;
+/**
+ * @brief The tizen core poll fd handle.
+ * @since_tizen 9.0
+ */
+typedef void *tizen_core_poll_fd_h;
+
/**
* @brief Called when the tizen core idle or timer event is emitted.
* @since_tizen 9.0
* @see tizen_core_source_set_dispatch_callback()
*/
typedef bool (*tizen_core_source_dispatch_cb)(tizen_core_source_h source,
- void *user_data);
+ void *user_data);
/**
* @brief Called when the source is finalizing.
* @see tizen_core_source_set_finalize_callback()
*/
typedef void (*tizen_core_source_finalize_cb)(tizen_core_source_h source,
- void *user_data);
-
-/**
- * @brief The structure type containing the set of variables for setting poll events.
- * @since_tizen 9.0
- *
- * @see tizen_core_source_add_poll()
- */
-typedef struct {
- int fd; /**< The file descriptor */
- short events; /**< The requested events */
- short revents; /**< The returned events */
-} tizen_core_poll_fd_s;
+ void *user_data);
/**
* @brief Initializes the tizen core.
* @details The tizen core source must be created using the tizen_core_source_create().
*
* @param[in] h The tizen core source handle
- * @param[in] poll_fd The polling file descriptor
+ * @param[in] poll_fd The poll fd handle
* @return @c 0 on success,
* otherwise a negative error value
* @retval #TIZEN_CORE_ERROR_NONE Successful
* @see tizen_core_source_remove_poll()
*/
int tizen_core_source_add_poll(tizen_core_source_h h,
- tizen_core_poll_fd_s poll_fd);
+ tizen_core_poll_fd_h poll_fd);
/**
* @brief Removes to waits for some events on the file descriptor.
* @details The tizen core source must be created using the tizen_core_source_create().
*
* @param[in] h The tizen core source handle
- * @param[in] poll_fd The polling file descriptor
+ * @param[in] poll_fd The poll fd handle
* @return @c 0 on success,
* otherwise a negative error value
* @retval #TIZEN_CORE_ERROR_NONE Successful
* @see tizen_core_source_add_poll()
*/
int tizen_core_source_remove_poll(tizen_core_source_h h,
- tizen_core_poll_fd_s poll_fd);
+ tizen_core_poll_fd_h poll_fd);
/**
* @brief Sets the prepare callback function to the tizen core source.
/**
* @brief Gets the poll fds from the tizen core source.
* @since_tizen 9.0
- * @details The @c poll_fds should be released using free().
*
* @param[in] h The tizen core source handle
* @param[out] poll_fds The polling file descriptors
* @see tizen_core_source_add_poll()
*/
int tizen_core_source_get_poll_fds(tizen_core_source_h h,
- tizen_core_poll_fd_s **poll_fds,
+ tizen_core_poll_fd_h *poll_fds,
unsigned int *length);
+/**
+ * @brief Creates a tizen core poll fd handle.
+ * @since_tizen 9.0
+ *
+ * @param[out] h The tizen core poll fd handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #TIZEN_CORE_ERROR_OUT_OF_MEMORY Out of memory
+ * @see tizen_core_poll_fd_destroy()
+ */
+int tizen_core_poll_fd_create(tizen_core_poll_fd_h *h);
+
+/**
+ * @brief Destroys the tizen core poll fd handle.
+ * @since_tizen 9.0
+ *
+ * @param[in] h The tizen core poll fd handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #TIZEN_CORE_ERROR_OUT_OF_MEMORY Out of memory
+ */
+int tizen_core_poll_fd_destroy(tizen_core_poll_fd_h h);
+
+/**
+ * @brief Sets the file descriptor to the poll fd handle.
+ * @since_tizen 9.0
+ *
+ * @param[in] h The tizen core poll fd handle
+ * @param[in] fd The file descriptor
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_RRROR_INVALID_PARAMETER Invalid parameter
+ * @see tizen_core_poll_fd_get_fd()
+ */
+int tizen_core_poll_fd_set_fd(tizen_core_poll_fd_h h, int fd);
+
+/**
+ * @brief Gets the file descriptor from the poll fd handle.
+ * @since_tizen 9.0
+ *
+ * @param[in] h The tizen core poll fd handle
+ * @param[out] fd The file descriptor
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_RRROR_INVALID_PARAMETER Invalid parameter
+ * @see tizen_core_poll_fd_set_fd()
+ */
+int tizen_core_poll_fd_get_fd(tizen_core_poll_fd_h h, int *fd);
+
+/**
+ * @brief Sets the requested events to the poll fd handle.
+ * @since_tizen 9.0
+ *
+ * @param[in] h The tizen core poll fd handle
+ * @param[in] events The requested events
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see tizen_core_poll_fd_get_events()
+ */
+int tizen_core_poll_fd_set_events(tizen_core_poll_fd_h h, uint16_t events);
+
+/**
+ * @brief Gets the requested events from the poll fd handle.
+ * @since_tizen 9.0
+ *
+ * @param[in] h The tizen core poll fd handle
+ * @param[out] events The requested events
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see tizen_core_poll_fd_set_events()
+ */
+int tizen_core_poll_fd_get_events(tizen_core_poll_fd_h h, uint16_t *events);
+
+/**
+ * @brief Sets the returned events to the poll fd handle.
+ * @since_tizen 9.0
+ *
+ * @param[in] h The tizen core poll fd handle
+ * @param[in] revents The returned events
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see tizen_core_poll_fd_get_events()
+ */
+int tizen_core_poll_fd_set_revents(tizen_core_poll_fd_h h, uint16_t revents);
+
+/**
+ * @brief Gets the returned events from the poll fd handle.
+ * @since_tizen 9.0
+ *
+ * @param[in] h The tizen core poll fd handle
+ * @param[out] revents The returned events
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see tizen_core_poll_fd_set_events()
+ */
+int tizen_core_poll_fd_get_revents(tizen_core_poll_fd_h h, uint16_t *revents);
+
#ifdef __cplusplus
}
#endif
TCoreSetUp();
TCoreChannelSetUp();
TCoreEventSetUp();
+ TCorePollFdSetUp();
}
void TearDown() override {
+ TCorePollFdTearDown();
TCoreEventTearDown();
TCoreChannelTearDown();
TCoreTearDown();
tizen_core_event_object_h event_object_ = nullptr;
int type_ = 0;
+ tizen_core_poll_fd_h poll_fd_ = nullptr;
+
private:
void TCoreSetUp() {
tizen_core_init();
event_ = nullptr;
}
}
+
+ void TCorePollFdSetUp() {
+ tizen_core_poll_fd_create(&poll_fd_);
+ tizen_core_poll_fd_set_fd(poll_fd_, 0);
+ tizen_core_poll_fd_set_events(poll_fd_, POLL_IN);
+ tizen_core_poll_fd_set_revents(poll_fd_, POLL_IN);
+ }
+
+ void TCorePollFdTearDown() {
+ if (poll_fd_ != nullptr) {
+ tizen_core_poll_fd_destroy(poll_fd_);
+ poll_fd_ = nullptr;
+ }
+ }
};
TEST_F(TizenCoreTest, tizen_core_init_P) {
}
TEST_F(TizenCoreTest, tizen_core_source_add_poll_P) {
- tizen_core_poll_fd_s poll_fd = { 0, POLL_IN, };
+ tizen_core_poll_fd_h poll_fd = nullptr;
+ tizen_core_poll_fd_create(&poll_fd);
+ ASSERT_NE(poll_fd, nullptr);
+ tizen_core_poll_fd_set_fd(poll_fd, 0);
+ tizen_core_poll_fd_set_events(poll_fd, POLL_IN);
+
int ret = tizen_core_source_add_poll(source_, poll_fd);
ASSERT_EQ(ret, TIZEN_CORE_ERROR_NONE);
+
+ tizen_core_source_remove_poll(source_, poll_fd);
+ tizen_core_poll_fd_destroy(poll_fd);
}
TEST_F(TizenCoreTest, tizen_core_source_add_poll_N) {
- tizen_core_poll_fd_s poll_fd = { 0, };
- int ret = tizen_core_source_add_poll(nullptr, poll_fd);
+ int ret = tizen_core_source_add_poll(nullptr, nullptr);
ASSERT_EQ(ret, TIZEN_CORE_ERROR_INVALID_PARAMETER);
}
ASSERT_EQ(context, nullptr);
ASSERT_EQ(get_last_result(), TIZEN_CORE_ERROR_INVALID_PARAMETER);
}
+
+TEST_F(TizenCoreTest, tizen_core_poll_fd_create_P) {
+ tizen_core_poll_fd_h poll_fd = nullptr;
+ int ret = tizen_core_poll_fd_create(&poll_fd);
+ ASSERT_EQ(ret, TIZEN_CORE_ERROR_NONE);
+ ASSERT_NE(poll_fd, nullptr);
+ tizen_core_poll_fd_destroy(poll_fd);
+}
+
+TEST_F(TizenCoreTest, tizen_core_poll_fd_create_N) {
+ int ret = tizen_core_poll_fd_create(nullptr);
+ ASSERT_EQ(ret, TIZEN_CORE_ERROR_INVALID_PARAMETER);
+}
+
+TEST_F(TizenCoreTest, tizen_core_poll_fd_destroy_P) {
+ int ret = tizen_core_poll_fd_destroy(poll_fd_);
+ ASSERT_EQ(ret, TIZEN_CORE_ERROR_NONE);
+ poll_fd_ = nullptr;
+}
+
+TEST_F(TizenCoreTest, tizen_core_poll_fd_destroy_N) {
+ int ret = tizen_core_poll_fd_destroy(nullptr);
+ ASSERT_EQ(ret, TIZEN_CORE_ERROR_INVALID_PARAMETER);
+}
+
+TEST_F(TizenCoreTest, tizen_core_poll_fd_set_and_get_fd_P) {
+ int ret = tizen_core_poll_fd_set_fd(poll_fd_, 1);
+ ASSERT_EQ(ret, TIZEN_CORE_ERROR_NONE);
+
+ int fd = -1;
+ ret = tizen_core_poll_fd_get_fd(poll_fd_, &fd);
+ ASSERT_EQ(ret, TIZEN_CORE_ERROR_NONE);
+ ASSERT_EQ(fd, 1);
+}
+
+TEST_F(TizenCoreTest, tizen_core_poll_fd_set_and_get_fd_N) {
+ int ret = tizen_core_poll_fd_set_fd(nullptr, -1);
+ ASSERT_EQ(ret, TIZEN_CORE_ERROR_INVALID_PARAMETER);
+
+ ret = tizen_core_poll_fd_get_fd(nullptr, nullptr);
+ ASSERT_EQ(ret, TIZEN_CORE_ERROR_INVALID_PARAMETER);
+}
+
+TEST_F(TizenCoreTest, tizen_core_poll_fd_set_and_get_events_P) {
+ int ret = tizen_core_poll_fd_set_events(poll_fd_, POLLIN);
+ ASSERT_EQ(ret, TIZEN_CORE_ERROR_NONE);
+
+ uint16_t events = 0;
+ ret = tizen_core_poll_fd_get_events(poll_fd_, &events);
+ ASSERT_EQ(ret, TIZEN_CORE_ERROR_NONE);
+ ASSERT_EQ(events, POLLIN);
+}
+
+TEST_F(TizenCoreTest, tizen_core_poll_fd_set_and_get_events_N) {
+ int ret = tizen_core_poll_fd_set_events(nullptr, 0);
+ ASSERT_EQ(ret, TIZEN_CORE_ERROR_INVALID_PARAMETER);
+
+ ret = tizen_core_poll_fd_get_events(nullptr, nullptr);
+ ASSERT_EQ(ret, TIZEN_CORE_ERROR_INVALID_PARAMETER);
+}
+
+TEST_F(TizenCoreTest, tizen_core_poll_fd_set_and_get_revents_P) {
+ int ret = tizen_core_poll_fd_set_revents(poll_fd_, POLLIN);
+ ASSERT_EQ(ret, TIZEN_CORE_ERROR_NONE);
+
+ uint16_t revents = 0;
+ ret = tizen_core_poll_fd_get_revents(poll_fd_, &revents);
+ ASSERT_EQ(ret, TIZEN_CORE_ERROR_NONE);
+ ASSERT_EQ(revents, POLLIN);
+}
+
+TEST_F(TizenCoreTest, tizen_core_poll_fd_set_and_get_revents_N) {
+ int ret = tizen_core_poll_fd_set_revents(nullptr, 0);
+ ASSERT_EQ(ret, TIZEN_CORE_ERROR_INVALID_PARAMETER);
+
+ ret = tizen_core_poll_fd_get_revents(nullptr, nullptr);
+ ASSERT_EQ(ret, TIZEN_CORE_ERROR_INVALID_PARAMETER);
+}
#include "tizen_base/poll_fd.h"
+#include "tizen_base/log_private.h"
+
namespace tizen_base {
namespace tizen_core {
-PollFd::PollFd(int fd, short events, short revents)
- : fd_(fd), events_(events), revents_(revents) {}
+PollFd::PollFd() { _D("PollFd=%p", this); }
+
+PollFd::~PollFd() { _D("PollFd=%p, fd=%d", this, gpollfd_.fd); }
+
+void PollFd::SetFd(int fd) { gpollfd_.fd = fd; }
+
+int PollFd::GetFd() const { return gpollfd_.fd; }
+
+void PollFd::SetEvents(uint16_t events) { gpollfd_.events = events; }
+
+uint16_t PollFd::GetEvents() const { return gpollfd_.events; }
+
+void PollFd::SetRevents(uint16_t revents) { gpollfd_.revents = revents; }
+
+uint16_t PollFd::GetRevents() const { return gpollfd_.revents; }
-int PollFd::GetFd() const {
- return fd_;
-}
+const GPollFD* PollFd::GetGPollFD() const { return &gpollfd_; }
-short PollFd::GetEvents() const {
- return events_;
-}
+void PollFd::RefSelf() { self_ = shared_from_this(); }
-short PollFd::GetRevents() const {
- return revents_;
-}
+void PollFd::UnrefSelf() { self_.reset(); }
} // namespace tizen_core
} // namespace tizen_base
#ifndef TIZEN_CORE_TIZEN_BASE_POLL_FD_H_
#define TIZEN_CORE_TIZEN_BASE_POLL_FD_H_
+#include <glib.h>
+
+#include <memory>
+
#undef EXPORT_API
#define EXPORT_API __attribute__((visibility("default")))
namespace tizen_base {
namespace tizen_core {
-class EXPORT_API PollFd {
+class EXPORT_API PollFd : public std::enable_shared_from_this<PollFd> {
public:
- PollFd(int fd, short events, short revents);
+ PollFd();
+ ~PollFd();
+ void SetFd(int fd);
int GetFd() const;
- short GetEvents() const;
- short GetRevents() const;
+
+ void SetEvents(uint16_t events);
+ uint16_t GetEvents() const;
+
+ void SetRevents(uint16_t revents);
+ uint16_t GetRevents() const;
+
+ const GPollFD* GetGPollFD() const;
+
+ void RefSelf();
+ void UnrefSelf();
private:
- int fd_;
- short events_;
- short revents_;
+ GPollFD gpollfd_ = { -1, 0, 0 };
+ std::shared_ptr<PollFd> self_;
};
} // namespace tizen_core
}
}
-void Source::AddPoll(const PollFd& pollfd) {
- auto* gpollfd = static_cast<GPollFD*>(g_malloc(sizeof(GPollFD)));
- if (gpollfd == nullptr) {
- _E("g_malloc() is failed");
- throw std::runtime_error("g_malloc() is failed");
- }
-
- gpollfd->fd = pollfd.GetFd();
- gpollfd->events = pollfd.GetEvents();
- gpollfd->revents = pollfd.GetRevents();
- g_source_add_poll(handle_, gpollfd);
+void Source::AddPoll(PollFd* poll_fd) {
+ _D("AddPoll(). PollFd=%p", poll_fd);
+ g_source_add_poll(handle_, const_cast<GPollFD*>(poll_fd->GetGPollFD()));
g_source_set_callback(handle_, nullptr, this, nullptr);
source_manager.Insert(this);
+ poll_fds_.push_back(poll_fd);
}
-void Source::RemovePoll(const PollFd& pollfd) {
- GSList* iter = handle_->poll_fds;
- while (iter != nullptr) {
- auto* gpollfd = static_cast<GPollFD*>(iter->data);
- if (gpollfd->fd == pollfd.GetFd() &&
- gpollfd->events == pollfd.GetEvents()) {
- g_source_remove_poll(handle_, gpollfd);
- g_free(gpollfd);
- break;
- }
-
- iter = g_slist_next(iter);
- }
+void Source::RemovePoll(PollFd* poll_fd) {
+ _D("RemovePoll(). PollFd=%p", poll_fd);
+ g_source_remove_poll(handle_, const_cast<GPollFD*>(poll_fd->GetGPollFD()));
+ auto found = std::find(poll_fds_.begin(), poll_fds_.end(), poll_fd);
+ if (found == poll_fds_.end()) return;
+ poll_fds_.erase(found);
}
void Source::Attach(const std::shared_ptr<Context>& context) {
g_source_set_priority(handle_, priority);
}
-GSList* Source::GetPollFds() const {
- if (handle_ == nullptr) return nullptr;
-
- return handle_->poll_fds;
+const std::vector<PollFd*>& Source::GetPollFds() const {
+ return poll_fds_;
}
bool Source::OnSourcePrepare(int* timeout) { return false; }
#include <glib.h>
#include <memory>
+#include <vector>
#include "tizen_base/context.h"
#include "tizen_base/interface_source.h"
explicit Source(GSource* handle);
virtual ~Source();
- void AddPoll(const PollFd& pollfd);
- void RemovePoll(const PollFd& pollfd);
+ void AddPoll(PollFd* poll_fd);
+ void RemovePoll(PollFd* poll_fd);
void Attach(const std::shared_ptr<Context>& context) override;
bool IsAttached() const;
GSource* GetHandle() const;
void RefSelf() override;
void UnrefSelf() override;
void SetPriority(int priority);
- GSList* GetPollFds() const;
+ const std::vector<PollFd*>& GetPollFds() const;
virtual bool OnSourcePrepare(int* timeout);
virtual bool OnSourceCheck();
GSource* handle_ = nullptr;
bool attached_ = false;
std::shared_ptr<Source> self_;
+ std::vector<PollFd*> poll_fds_;
};
} // namespace tizen_core
}
API int tizen_core_source_add_poll(tizen_core_source_h h,
- tizen_core_poll_fd_s poll_fd) {
- if (h == nullptr) {
+ tizen_core_poll_fd_h poll_fd) {
+ if (h == nullptr || poll_fd == nullptr) {
_E("Invalid parameter");
return TIZEN_CORE_ERROR_INVALID_PARAMETER;
}
auto* source = static_cast<SourceExt*>(h);
- tizen_base::tizen_core::PollFd pollfd(poll_fd.fd, poll_fd.events,
- poll_fd.revents);
- try {
- source->AddPoll(pollfd);
- } catch (const std::runtime_error& e) {
- _E("runtime_error occurs. error(%s)", e.what());
- return TIZEN_CORE_ERROR_INVALID_CONTEXT;
- }
-
+ source->AddPoll(static_cast<tizen_base::tizen_core::PollFd*>(poll_fd));
return TIZEN_CORE_ERROR_NONE;
}
API int tizen_core_source_remove_poll(tizen_core_source_h h,
- tizen_core_poll_fd_s poll_fd) {
- if (h == nullptr) {
+ tizen_core_poll_fd_h poll_fd) {
+ if (h == nullptr || poll_fd == nullptr) {
_E("Invalid parameter");
return TIZEN_CORE_ERROR_INVALID_PARAMETER;
}
auto* source = static_cast<SourceExt*>(h);
- tizen_base::tizen_core::PollFd pollfd(poll_fd.fd, poll_fd.events,
- poll_fd.revents);
- try {
- source->RemovePoll(pollfd);
- } catch (const std::runtime_error& e) {
- _E("runtime_error occurs. error(%s)", e.what());
- return TIZEN_CORE_ERROR_INVALID_CONTEXT;
- }
-
+ source->RemovePoll(static_cast<tizen_base::tizen_core::PollFd*>(poll_fd));
return TIZEN_CORE_ERROR_NONE;
}
}
API int tizen_core_source_get_poll_fds(tizen_core_source_h h,
- tizen_core_poll_fd_s** poll_fds,
+ tizen_core_poll_fd_h* poll_fds,
unsigned int* length) {
if (h == nullptr || poll_fds == nullptr || length == nullptr) {
_E("Invalid parameter");
}
auto* source = static_cast<SourceExt*>(h);
- guint len = g_slist_length(source->GetPollFds());
- auto* fds = static_cast<tizen_core_poll_fd_s*>(
- calloc(len, sizeof(tizen_core_poll_fd_s)));
- if (fds == nullptr) {
+ auto& fds = source->GetPollFds();
+ *poll_fds = static_cast<tizen_core_poll_fd_h>(
+ const_cast<tizen_base::tizen_core::PollFd**>(fds.data()));
+ *length = fds.size();
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_poll_fd_create(tizen_core_poll_fd_h* h) {
+ if (h == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto poll_fd = std::make_shared<tizen_base::tizen_core::PollFd>();
+ if (poll_fd == nullptr) {
_E("Out of memory");
return TIZEN_CORE_ERROR_OUT_OF_MEMORY;
}
- int index = 0;
- auto* iter = source->GetPollFds();
- while (iter != nullptr) {
- auto* gpoll_fd = static_cast<GPollFD*>(iter->data);
- fds[index].fd = gpoll_fd->fd;
- fds[index].events = gpoll_fd->events;
- fds[index++].revents = gpoll_fd->revents;
- iter = g_slist_next(iter);
+ poll_fd->RefSelf();
+ *h = static_cast<tizen_core_poll_fd_h>(poll_fd.get());
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_poll_fd_destroy(tizen_core_poll_fd_h h) {
+ if (h == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* poll_fd = static_cast<tizen_base::tizen_core::PollFd*>(h);
+ poll_fd->UnrefSelf();
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_poll_fd_set_fd(tizen_core_poll_fd_h h, int fd) {
+ if (h == nullptr || fd < 0) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* poll_fd = static_cast<tizen_base::tizen_core::PollFd*>(h);
+ poll_fd->SetFd(fd);
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_poll_fd_get_fd(tizen_core_poll_fd_h h, int* fd) {
+ if (h == nullptr || fd == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* poll_fd = static_cast<tizen_base::tizen_core::PollFd*>(h);
+ *fd = poll_fd->GetFd();
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+
+API int tizen_core_poll_fd_set_events(tizen_core_poll_fd_h h, uint16_t events) {
+ if (h == nullptr || events == 0) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* poll_fd = static_cast<tizen_base::tizen_core::PollFd*>(h);
+ poll_fd->SetEvents(events);
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_poll_fd_get_events(tizen_core_poll_fd_h h,
+ uint16_t* events) {
+ if (h == nullptr || events == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* poll_fd = static_cast<tizen_base::tizen_core::PollFd*>(h);
+ *events = poll_fd->GetEvents();
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_poll_fd_set_revents(tizen_core_poll_fd_h h,
+ uint16_t revents) {
+ if (h == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* poll_fd = static_cast<tizen_base::tizen_core::PollFd*>(h);
+ poll_fd->SetRevents(revents);
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_poll_fd_get_revents(tizen_core_poll_fd_h h,
+ uint16_t* revents) {
+ if (h == nullptr || revents == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
}
- *poll_fds = fds;
- *length = len;
+ auto* poll_fd = static_cast<tizen_base::tizen_core::PollFd*>(h);
+ *revents = poll_fd->GetRevents();
return TIZEN_CORE_ERROR_NONE;
}