Added a tutorial and fix few errors
[src/app-framework-binder.git] / include / afb / c++ / binding-object.hpp
index 307189b..1744535 100644 (file)
@@ -57,12 +57,12 @@ namespace afb
                /**
                 * @brief TApi's method pointer.
                 */
-               using TVerbCallback = void(TApi::*)(afb_req_t);
+               using TVerbCallback = void(TApi::*)(req);
 
                /***
                 * @brief TApi's const method pointer.
                 */
-               using TVerbCallbackConst = void(TApi::*)(afb_req_t) const;
+               using TVerbCallbackConst = void(TApi::*)(req) const;
 
                /**
                 * @brief Pre-init callback for an api created using @c afb::api::new_api.
@@ -91,7 +91,7 @@ namespace afb
                                return -2;
                        }
 
-                       api->handle_ = handle;
+                       api->api_ = handle;
                        return api->preinit(handle);
                }
 
@@ -131,30 +131,30 @@ namespace afb
                /**
                 * @brief Verb callback for a verb added using @c afb::api::add_verb.
                 * @tparam callback TApi's method to call
-                * @param[in] req Request to handle.
+                * @param[in] r Request to handle.
                 */
                template <TVerbCallback callback>
-               static void verb(afb_req_t req)
+               static void verb(afb_req_t r)
                {
-                       assert(req != nullptr);
+                       assert(r != nullptr);
 
-                       afb_api_t handle = afb_req_get_api(req);
+                       afb_api_t handle = afb_req_get_api(r);
                        if (handle)
                        {
                                void* userdata = afb_api_get_userdata(handle);
                                if (userdata)
                                {
                                        TApi* api = reinterpret_cast<TApi*>(userdata);
-                                       (api->*callback)(req);
+                                       (api->*callback)(afb::req(r));
                                }
                                else
                                {
-                                       afb_req_fail(req, "Failed to get the API object!", nullptr);
+                                       afb_req_fail(r, "Failed to get the API object!", nullptr);
                                }
                        }
                        else
                        {
-                               afb_req_fail(req, "Failed to get the corresponding API from the query!", nullptr);
+                               afb_req_fail(r, "Failed to get the corresponding API from the query!", nullptr);
                        }
                }
 
@@ -164,27 +164,27 @@ namespace afb
                 * @param[in] req Request to handle.
                 */
                template <TVerbCallbackConst callback>
-               static void verb(afb_req_t req)
+               static void verb(afb_req_t r)
                {
-                       assert(req != nullptr);
+                       assert(r != nullptr);
 
-                       afb_api_t handle = afb_req_get_api(req);
+                       afb_api_t handle = afb_req_get_api(r);
                        if (handle)
                        {
                                void* userdata = afb_api_get_userdata(handle);
                                if (userdata)
                                {
                                        TApi* api = reinterpret_cast<TApi*>(userdata);
-                                       (api->*callback)(req);
+                                       (api->*callback)(afb::req(r));
                                }
                                else
                                {
-                                       afb_req_fail(req, "Failed to get the API object!", nullptr);
+                                       afb_req_fail(r, "Failed to get the API object!", nullptr);
                                }
                        }
                        else
                        {
-                               afb_req_fail(req, "Failed to get the corresponding API from the query!", nullptr);
+                               afb_req_fail(r, "Failed to get the corresponding API from the query!", nullptr);
                        }
                }
        };
@@ -212,8 +212,6 @@ namespace afb
                base_api_t& operator=(const base_api_t&) = delete;
 
        protected:
-               afb_api_t handle_;
-
                /**
                 * @brief Default constructor.
                 */
@@ -238,7 +236,7 @@ namespace afb
                int add_verb(const std::string& verb, const std::string& info, void* vcbdata = nullptr, const struct afb_auth* auth = nullptr, uint32_t session = AFB_SESSION_NONE_X2, int glob = 0)
                {
                        return afb_api_add_verb(
-                               handle_,
+                               api_,
                                verb.c_str(),
                                info == "" ? nullptr : info.c_str(),
                                TTraits::template verb<Callback>,
@@ -263,7 +261,7 @@ namespace afb
                int add_verb(const std::string& verb, const std::string& info, void* vcbdata = nullptr, const struct afb_auth* auth = nullptr, uint32_t session = AFB_SESSION_NONE_X2, int glob = 0)
                {
                        return afb_api_add_verb(
-                               handle_,
+                               api_,
                                verb.c_str(),
                                info == "" ? nullptr : info.c_str(),
                                TTraits::template verb<Callback>,
@@ -284,21 +282,21 @@ namespace afb
                 * @brief Get the API's handle.
                 * @return The API's handle.
                 */
-               afb_api_t handle() const { return handle_; }
+               afb_api_t handle() const { return api_; }
 
                /**
                 * @brief Implicit conversion to C handle.
                 * @return The API's handle.
                 */
-               operator afb_api_t() const { return handle_; }
+               operator afb_api_t() const { return api_; }
 
                /**
                 * @brief Destructor.
                 */
                virtual ~base_api_t()
                {
-                       if (handle_ && afb_api_delete_api(handle_))
-                               AFB_API_ERROR(handle_, "Failed to delete API.");
+                       if (api_ && afb_api_delete_api(api_))
+                               AFB_API_ERROR(api_, "Failed to delete API.");
                }
 
                /**