Type registry changed C# callback signatures 32/101932/6
authorNick Holland <nick.holland@partner.samsung.com>
Fri, 2 Dec 2016 11:02:29 +0000 (11:02 +0000)
committerNick Holland <nick.holland@partner.samsung.com>
Thu, 15 Dec 2016 10:23:36 +0000 (10:23 +0000)
To save memory / simplicity we now use just 3 C# delegates to
connect between C# and C++ type registry. Previously it was
3 delegates per custom control ( Create, Property Set, Property Get).

Change-Id: I91a1da13014449f2589b6f5f5f3cea6308a4c582

automated-tests/src/dali/utc-Dali-CSharp-TypeRegistry.cpp
dali/devel-api/object/csharp-type-info.h
dali/devel-api/object/csharp-type-registry.cpp
dali/devel-api/object/csharp-type-registry.h
dali/internal/event/common/type-info-impl.cpp
dali/internal/event/common/type-registry-impl.cpp
dali/internal/event/common/type-registry-impl.h

index bf97f9f..67272f3 100644 (file)
@@ -32,7 +32,9 @@ namespace
 
 
 static bool CreateCustomNamedInitCalled = false;
-BaseHandle* CreateCustomNamedInit(void)
+
+
+BaseHandle* CreateCustomNamedInit(const char* const typeName )
 {
   CreateCustomNamedInitCalled = true;
 
@@ -45,14 +47,16 @@ BaseHandle* CreateCustomNamedInit(void)
 bool setPropertyCalled = false;
 bool getPropertyCalled = false;
 int intPropertyValue = 0;
-void SetProperty( BaseObject* object, Property::Index* index, Property::Value* value )
+
+void SetProperty( BaseObject* object, const char* const propertyName , Property::Value* value )
 {
 
   value->Get( intPropertyValue );
 
   setPropertyCalled = true;
 }
-Property::Value* GetProperty( BaseObject* object, Property::Index* index )
+
+Property::Value* GetProperty( BaseObject* object, const char* const propertyName )
 {
   getPropertyCalled = true;
   Property::Value* x = new Property::Value( 10 );
@@ -66,9 +70,11 @@ int UtcDaliRegisterCSharpTypeP(void)
 
   TestApplication application;
 
-  CSharpTypeRegistry::RegisterType( "CSharpControl", typeid( Dali::Actor), &CreateCustomNamedInit, true );
+  CSharpTypeRegistry::RegisterType( "CSharpControl", typeid( Dali::Actor), &CreateCustomNamedInit  );
 
-  GetImplementation(Dali::TypeRegistry::Get()).CallInitFunctions();
+  Dali::TypeInfo info = Dali::TypeRegistry::Get().GetTypeInfo( "CSharpControl" );
+
+  info.CreateInstance();
 
   DALI_TEST_EQUALS( CreateCustomNamedInitCalled, true, TEST_LOCATION );
 
@@ -79,9 +85,10 @@ int UtcDaliRegisterCSharpTypeNoInitP(void)
 {
 
   TestApplication application;
+
   CreateCustomNamedInitCalled = false;
 
-  CSharpTypeRegistry::RegisterType( "CSharpControl", typeid( Dali::Actor), &CreateCustomNamedInit, false);
+  CSharpTypeRegistry::RegisterType( "CSharpControl", typeid( Dali::Actor), &CreateCustomNamedInit );
 
   GetImplementation(Dali::TypeRegistry::Get()).CallInitFunctions();
 
@@ -94,12 +101,12 @@ int UtcDaliRegisterCSharpTypeN(void)
 {
   TestApplication application;
 
-  CSharpTypeRegistry::RegisterType( "CSharpControl", typeid( Dali::Actor), &CreateCustomNamedInit, true );
+  CSharpTypeRegistry::RegisterType( "CSharpControl", typeid( Dali::Actor), &CreateCustomNamedInit );
 
   // should cause an assert because we're registering same type twice
   try
   {
-    CSharpTypeRegistry::RegisterType( "CSharpControl", typeid( Dali::Actor), &CreateCustomNamedInit, true );
+    CSharpTypeRegistry::RegisterType( "CSharpControl", typeid( Dali::Actor), &CreateCustomNamedInit );
     tet_result( TET_FAIL );
   }
   catch ( DaliException& e )
@@ -116,13 +123,11 @@ int UtcDaliRegisterCSharpTypeCreateP(void)
   TestApplication application;
   CreateCustomNamedInitCalled = false;
 
-  CSharpTypeRegistry::RegisterType( "CSharpControl", typeid( Dali::Actor), &CreateCustomNamedInit, false);
+  CSharpTypeRegistry::RegisterType( "CSharpControl", typeid( Dali::Actor), &CreateCustomNamedInit );
 
 
   TypeInfo info = Dali::TypeRegistry::Get().GetTypeInfo( "CSharpControl");
 
-
-
   BaseHandle handle = info.CreateInstance();
 
   DALI_TEST_EQUALS( CreateCustomNamedInitCalled, true, TEST_LOCATION );
@@ -136,7 +141,7 @@ int UtcDaliRegisterCSharpPropertyP(void)
 {
   TestApplication application;
 
-  CSharpTypeRegistry::RegisterType( "DateControl", typeid( Dali::Actor), &CreateCustomNamedInit, true );
+  CSharpTypeRegistry::RegisterType( "DateControl", typeid( Dali::Actor), &CreateCustomNamedInit );
 
 
   bool registered = CSharpTypeRegistry::RegisterProperty( "DateControl",
@@ -158,7 +163,7 @@ int UtcDaliRegisterCSharpPropertyN(void)
   TestApplication application;
 
   // register the same property twice
-  CSharpTypeRegistry::RegisterType( "DateControl", typeid( Dali::Actor), &CreateCustomNamedInit, true );
+  CSharpTypeRegistry::RegisterType( "DateControl", typeid( Dali::Actor), &CreateCustomNamedInit );
 
 
   bool registered = CSharpTypeRegistry::RegisterProperty( "DateControl",
@@ -196,7 +201,7 @@ int UtcDaliRegisterCSharpPropertySetP(void)
   TestApplication application;
 
    // register the same property twice
-   CSharpTypeRegistry::RegisterType( "DateControl", typeid( Dali::Actor), &CreateCustomNamedInit, true );
+   CSharpTypeRegistry::RegisterType( "DateControl", typeid( Dali::Actor), &CreateCustomNamedInit );;
 
    Property::Index index(100001);
 
@@ -238,7 +243,7 @@ int UtcDaliRegisterCSharpPropertyGetP(void)
   TestApplication application;
 
    // register the same property twice
-   CSharpTypeRegistry::RegisterType( "DateControl", typeid( Dali::Actor), &CreateCustomNamedInit, true );
+   CSharpTypeRegistry::RegisterType( "DateControl", typeid( Dali::Actor), &CreateCustomNamedInit );
 
    Property::Index index(100001);
 
index 7f7831d..49472f1 100644 (file)
@@ -28,28 +28,34 @@ namespace Dali
 namespace CSharpTypeInfo
 {
 
-  typedef BaseHandle* (*CreateFunction)(); ///< Function signature for creating an instance of the associated object type
+  /**
+   * @brief Call back used to create an instance of the associated object type
+   *
+   * @param[in] typeName The type name of the object to be created.
+   * @return Pointer to a BaseHandle
+   */
+  typedef BaseHandle* (*CreateFunction)(const char* const typeName);
 
   /**
    * @brief Callback to set an event-thread only property.
    *
    * @param[in] object The object whose property should be set.
-   * @param[in] index The index of the property being set.
+   * @param[in] propertyName The name of the property required.
    * @param[in] value The new value of the property for the object specified.
    * @see PropertyRegistration.
    */
-  typedef void (*SetPropertyFunction)( BaseObject* object, Property::Index* index, Property::Value* value );
+  typedef void (*SetPropertyFunction)( BaseObject* object, const char* const propertyName , Property::Value* value );
 
 
   /**
    * @brief Callback to get the value of an event-thread only property.
    *
    * @param[in] object The object whose property value is required.
-   * @param[in] index The index of the property required.
+   * @param[in] propertyName The name of the property required.
    * @return The current value of the property for the object specified.
    * @see PropertyRegistration.
    */
-  typedef Property::Value* (*GetPropertyFunction)( BaseObject* object, Property::Index* index );
+  typedef Property::Value* (*GetPropertyFunction)( BaseObject* object, const char* const propertyName );
 }
 
 
index 0d058b5..bee45d8 100644 (file)
@@ -27,11 +27,11 @@ namespace Dali
 namespace CSharpTypeRegistry
 {
 
-bool RegisterType( const std::string& name, const std::type_info& baseType, CSharpTypeInfo::CreateFunction f, bool callCreateOnInit )
+bool RegisterType( const std::string& name, const std::type_info& baseType, CSharpTypeInfo::CreateFunction f )
 {
   Internal::TypeRegistry *impl = Internal::TypeRegistry::Get();
 
-  return impl->Register( name, baseType, f, callCreateOnInit );
+  return impl->Register( name, baseType, f );
 }
 
 bool RegisterProperty( const std::string& objectName,
index 156ecb5..c5e7810 100644 (file)
@@ -46,13 +46,11 @@ namespace CSharpTypeRegistry
  * @param [in] name the name of the type to be registered
  * @param [in] baseType the base type info of registerType
  * @param [in] f registerType instance creation function
- * @param [in] callCreateOnInit If true the creation function is called as part of Dali initialisation
  * @return true if the name could be registered.
  */
   DALI_IMPORT_API bool RegisterType( const std::string& name,
                                      const std::type_info& baseType,
-                                     CSharpTypeInfo::CreateFunction f,
-                                     bool callCreateOnInit );
+                                     CSharpTypeInfo::CreateFunction f );
 
   /**
    * Register an event-thread only property with a type (used by C# Custom controls)
index 2c7301e..fec8ead 100644 (file)
@@ -131,7 +131,9 @@ BaseHandle TypeInfo::CreateInstance() const
   {
     if ( mCSharpType )
     {
-      ret = *mCSharpCreate();
+      // CSharp currently only registers one create function for all custom controls
+      // it uses the type name to decide which one to create
+      ret = *mCSharpCreate( mTypeName.c_str() );
     }
     else
     {
@@ -750,7 +752,17 @@ void TypeInfo::SetProperty( BaseObject *object, Property::Index index, const Pro
   {
     if( iter->second.setFunc )
     {
-      iter->second.setFunc( object, index, value );
+      if( mCSharpType )
+      {
+        // CSharp wants a property name not an index
+        const std::string& name = (iter->second).name;
+
+        iter->second.cSharpSetFunc( object,name.c_str(), const_cast< Property::Value* >(&value) );
+      }
+      else
+      {
+        iter->second.setFunc( object, index, value );
+      }
     }
   }
   else
@@ -774,7 +786,16 @@ void TypeInfo::SetProperty( BaseObject *object, const std::string& name, const P
   if ( iter != mRegisteredProperties.end() )
   {
     DALI_ASSERT_ALWAYS( iter->second.setFunc && "Trying to write to a read-only property" );
-    iter->second.setFunc( object, iter->first, value );
+
+    if( mCSharpType )
+    {
+      // CSharp wants a property name not an index
+      iter->second.cSharpSetFunc( object,name.c_str(), const_cast< Property::Value* >(&value ));
+    }
+    else
+    {
+      iter->second.setFunc( object, iter->first, value );
+    }
   }
   else
   {
@@ -798,10 +819,12 @@ Property::Value TypeInfo::GetProperty( const BaseObject *object, Property::Index
   {
     if( mCSharpType ) // using csharp property get which returns a pointer to a Property::Value
     {
-       // CSharp can't return any object by value, it can return pointers.
-       // CSharp has ownership of the pointer contents, which is fine because we are returning by value
-       int index = (iter->first );
-       return *( iter->second.cSharpGetFunc( const_cast< BaseObject* >( object ), &index  ));
+      // CSharp wants a property name not an index
+      // CSharp callback can't return an object by value, it can only return a pointer
+      // CSharp has ownership of the pointer contents, which is fine because we are returning by from this function by value
+      const std::string& name = (iter->second).name;
+
+      return *( iter->second.cSharpGetFunc( const_cast< BaseObject* >( object ), name.c_str()) );
 
     }
     else
@@ -823,15 +846,18 @@ Property::Value TypeInfo::GetProperty( const BaseObject *object, Property::Index
 Property::Value TypeInfo::GetProperty( const BaseObject *object, const std::string& name ) const
 {
   RegisteredPropertyContainer::const_iterator iter = find_if( mRegisteredProperties.begin(), mRegisteredProperties.end(),
-                                                          PropertyNameFinder< RegisteredPropertyPair >( name ) );
+                                                            PropertyNameFinder< RegisteredPropertyPair >( name ) );
+
+
+
   if( iter != mRegisteredProperties.end() )
   {
     if( mCSharpType ) // using csharp property get which returns a pointer to a Property::Value
     {
-      // CSharp can't return any object by value, it can return pointers.
-      // CSharp has ownership of the pointer contents, which is fine because we are returning by value
-      int index = (iter->first );
-      return *( iter->second.cSharpGetFunc( const_cast< BaseObject* >( object ), &index ));
+       // CSharp wants a property name not an index
+       // CSharp callback can't return an object by value, it can only return a pointer
+       // CSharp has ownership of the pointer contents, which is fine because we are returning by from this function by value
+       return *( iter->second.cSharpGetFunc( const_cast< BaseObject* >( object ), name.c_str() ));
 
     }
     else
index dd947a2..5d61e49 100644 (file)
@@ -158,7 +158,7 @@ bool TypeRegistry::Register( const std::string& uniqueTypeName, const std::type_
 }
 
 bool TypeRegistry::Register( const std::string& uniqueTypeName, const std::type_info& baseTypeInfo,
-    Dali::CSharpTypeInfo::CreateFunction createInstance, bool callCreateOnInit  )
+    Dali::CSharpTypeInfo::CreateFunction createInstance )
 {
 
   bool ret = false;
@@ -178,10 +178,7 @@ bool TypeRegistry::Register( const std::string& uniqueTypeName, const std::type_
     DALI_LOG_WARNING("Duplicate name for TypeRegistry for '%s'\n", + uniqueTypeName.c_str());
     DALI_ASSERT_ALWAYS(!"Duplicate type name for Type Registation");
   }
-  if( callCreateOnInit )
-  {
-    mCSharpInitFunctions.push_back(createInstance);
-  }
+
   return ret;
 
 }
@@ -192,10 +189,6 @@ void TypeRegistry::CallInitFunctions(void) const
   {
     (*iter)();
   }
-  for( CSharpInitFunctions::const_iterator iter = mCSharpInitFunctions.begin(); iter != mCSharpInitFunctions.end(); ++iter)
-  {
-    (*iter)();
-  }
 }
 
 std::string TypeRegistry::RegistrationName( const std::type_info& registerType )
index 815d0da..0690de2 100644 (file)
@@ -93,11 +93,10 @@ public:
    * @param [in] name The name type to be registered (must be unique)
    * @param [in] baseTypeInfo Type info for its base class
    * @param [in] createInstance Instance creation function
-   * @param [in] callCreateOnInit If true call createInstance on dali initialisation
    * @return true if the name could be registered.
    */
   bool Register( const std::string& name, const std::type_info& baseTypeInfo,
-                 Dali::CSharpTypeInfo::CreateFunction createInstance, bool callCreateOnInit );
+                 Dali::CSharpTypeInfo::CreateFunction createInstance );
 
   /*
    * Register a signal connector function to a type
@@ -224,9 +223,6 @@ private:
   typedef std::vector<Dali::TypeInfo::CreateFunction> InitFunctions;
   InitFunctions mInitFunctions;
 
-  typedef std::vector<Dali::CSharpTypeInfo::CreateFunction> CSharpInitFunctions;
-  CSharpInitFunctions mCSharpInitFunctions;
-
 private:
   TypeRegistry();
   ~TypeRegistry();