From fffff493262e7cc88e4d95b15239fc61b283542d Mon Sep 17 00:00:00 2001 From: Agnelo Vaz Date: Tue, 8 Jan 2019 19:59:32 +0000 Subject: [PATCH] Adding LayoutController and bindings Change-Id: I02c82ecaddbb6322627259dd4575573f5623df72 --- dali-csharp-binder/file.list | 1 + dali-csharp-binder/src/layout-controller.cpp | 134 +++++++++++++++++++++++++++ dali-csharp-binder/src/layout-controller.h | 72 ++++++++++++++ 3 files changed, 207 insertions(+) create mode 100644 dali-csharp-binder/src/layout-controller.cpp create mode 100644 dali-csharp-binder/src/layout-controller.h diff --git a/dali-csharp-binder/file.list b/dali-csharp-binder/file.list index f7effb1..d7149a1 100755 --- a/dali-csharp-binder/file.list +++ b/dali-csharp-binder/file.list @@ -11,6 +11,7 @@ dali_csharp_binder_common_src_files = \ ${dali_csharp_binder_dir}/src/keyboard_focus_manager_wrap.cpp \ ${dali_csharp_binder_dir}/src/devel-property-wrap.cpp \ ${dali_csharp_binder_dir}/src/version-check.cpp \ + ${dali_csharp_binder_dir}/src/layout-controller.cpp \ ${dali_csharp_binder_dir}/src/layout-length.cpp \ ${dali_csharp_binder_dir}/src/layout-size.cpp \ ${dali_csharp_binder_dir}/src/layout-measured-size.cpp \ diff --git a/dali-csharp-binder/src/layout-controller.cpp b/dali-csharp-binder/src/layout-controller.cpp new file mode 100644 index 0000000..b564c15 --- /dev/null +++ b/dali-csharp-binder/src/layout-controller.cpp @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "layout-controller.h" +#include + +#ifdef __cplusplus +extern "C" { +#endif + +namespace +{ +static int gLayoutControllerId = 1; +} // unnamed namespace + +LayoutController::LayoutController() : mId( gLayoutControllerId++ ) +{ + Dali::Adaptor::Get().RegisterProcessor(*this); +} + + +LayoutController::~LayoutController() +{ + Dali::Adaptor::Get().UnregisterProcessor(*this); +} + + +int LayoutController::GetId() const +{ + return mId; +} + +void LayoutController::Process() +{ + if( handler ) + { + handler( mId ); + } +} + +void LayoutController::SetCallback( LayoutControllerProcessCallback callback ) +{ + handler = callback; +} + +// LayoutController Bindings + +SWIGEXPORT void * SWIGSTDCALL CSharp_Dali_new_LayoutController() { + + LayoutController *result = 0 ; + + { + try { + result = (LayoutController *)new LayoutController(); + } catch (std::out_of_range& e) { + { + SWIG_CSharpException(SWIG_IndexError, const_cast(e.what())); return 0; + }; + } catch (std::exception& e) { + { + SWIG_CSharpException(SWIG_RuntimeError, const_cast(e.what())); return 0; + }; + } catch (Dali::DaliException e) { + { + SWIG_CSharpException(SWIG_UnknownError, e.condition); return 0; + }; + } catch (...) { + { + SWIG_CSharpException(SWIG_UnknownError, "unknown error"); return 0; + }; + } + } + + return (void *)result; +} + +SWIGEXPORT void SWIGSTDCALL CSharp_Dali_delete_LayoutController(void * jarg1) { + + LayoutController * arg1 = (LayoutController *)jarg1; + { + try { + delete arg1; + } catch (std::out_of_range& e) { + { + SWIG_CSharpException(SWIG_IndexError, const_cast(e.what())); return ; + }; + } catch (std::exception& e) { + { + SWIG_CSharpException(SWIG_RuntimeError, const_cast(e.what())); return ; + }; + } catch (...) { + { + SWIG_CSharpException(SWIG_UnknownError, "unknown error"); return ; + }; + } + } +} + +SWIGEXPORT void * SWIGSTDCALL CSharp_Dali_LayoutController_SetCallback( void* jarg1, LayoutController::LayoutControllerProcessCallback callback ) +{ + LayoutController* layoutController = (LayoutController *) jarg1; + + if( layoutController ) + { + layoutController->SetCallback( callback ); + } +} + +SWIGEXPORT void * SWIGSTDCALL CSharp_Dali_LayoutController_GetId( void* jarg1 ) +{ + LayoutController * layoutController = (LayoutController *)jarg1; + if( layoutController ) + { + layoutController->GetId(); + } +} + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/dali-csharp-binder/src/layout-controller.h b/dali-csharp-binder/src/layout-controller.h new file mode 100644 index 0000000..a3fff0d --- /dev/null +++ b/dali-csharp-binder/src/layout-controller.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// EXTERNAL INCLUDES +#include + +// INTERNAL INCLUDES +#include "common.h" + +/** + * @brief Implements a Integration::Processor interface so can be registered with dali-core as + * a Processor. Enables the setting of a callback so dali-core can execute this callback when + * Process() is run. + */ +class LayoutController : public Dali::Integration::Processor +{ +public: + + // Function pointer matching delegate in C# LayoutController + using LayoutControllerProcessCallback = void (SWIGSTDCALL*)(int); + +public: + /** + * @brief Constructor - creates a LayoutController and registers it with dali-core. + * + */ + LayoutController(); + + /** + * @brief Destructor - Unregisters itself from dali-core. + */ + ~LayoutController(); + + /** + * @brief Gets the id of the LayoutController that was initialised during construction. + * @return the id of the LayoutController. + * @note Useful for debugging when multiple LayoutControllers are registered with dali-core. + */ + int GetId() const; + + /** + * @copydoc Dali::Integration::Processor::Process() + */ + void Process() override; + + /** + * @brief Set the callback to be executed when dali-core calls the overriden Process() api. + * @param[in] callback, function to be called + */ + void SetCallback( LayoutControllerProcessCallback callback ); + +private: + + LayoutControllerProcessCallback handler; + + int mId; + +}; \ No newline at end of file -- 2.7.4