Devirtualize DescriptorSet
[platform/core/security/key-manager.git] / src / manager / client-async / descriptor-set.h
index 931d10d..de8e24b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  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.
@@ -34,8 +34,8 @@ public:
        // 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() {}
@@ -45,10 +45,10 @@ protected:
 /**
  * @brief Wrapper for poll()
  */
-class DescriptorSet : public IDescriptorSet {
+class DescriptorSet final : public IDescriptorSet {
 public:
        DescriptorSet();
-       virtual ~DescriptorSet();
+       ~DescriptorSet();
 
        NONCOPYABLE(DescriptorSet);
 
@@ -61,19 +61,19 @@ public:
         * @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
@@ -87,7 +87,7 @@ public:
        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);
@@ -106,4 +106,11 @@ protected:
        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 */