/*
- * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2000-2019 Samsung Electronics Co., Ltd. All rights reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
// int is for descriptor, short is for revents,
typedef std::function<void(int, short)> Callback;
- virtual void add(int fd, short events, Callback &&callback) = 0;
- virtual void remove(int fd, bool close_fd = true) = 0;
+ void add(int fd, short events, Callback &&callback);
+ void remove(int fd, bool close_fd = true);
protected:
// I don't want anyone to manage object lifetime via interface.
IDescriptorSet() {}
/**
* @brief Wrapper for poll()
*/
-class DescriptorSet : public IDescriptorSet {
+class DescriptorSet final : public IDescriptorSet {
public:
DescriptorSet();
- virtual ~DescriptorSet();
+ ~DescriptorSet();
NONCOPYABLE(DescriptorSet);
* @param events events to watch for
* @param callback callback to be called when an event on descriptor occurs
*/
- virtual void add(int fd, short events, Callback &&callback);
+ void add(int fd, short events, Callback &&callback);
/*
* Removes give descriptor from watched set and closes it.
*
* @param fd descriptor to be removed and closed
*/
- virtual void remove(int fd, bool close_fd = true);
+ void remove(int fd, bool close_fd = true);
/*
* Wait for descriptor events using poll().
* Synchronously calls provided descriptor callbacks.
*
- * @param timeout_ms timeout in ms. egative value means no timeout.
+ * @param timeout_ms timeout in ms. negative value means no timeout.
*
* @throws Timeout exception in case of timeout
* @throws InternalError in case of other error
DECLARE_EXCEPTION_TYPE(CKM::Exception, InternalError);
DECLARE_EXCEPTION_TYPE(CKM::Exception, Timeout);
-protected:
+private:
// returns false if there are no descriptors to wait for
bool rebuildPollfd();
void notify(int descCount);
pollfd *m_fds;
};
+inline void IDescriptorSet::add(int fd, short events, Callback &&callback) {
+ static_cast<DescriptorSet*>(this)->add(fd, events, std::move(callback));
+}
+inline void IDescriptorSet::remove(int fd, bool close_fd) {
+ static_cast<DescriptorSet*>(this)->remove(fd, close_fd);
+}
+
} /* namespace CKM */