2 * Copyright(c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 using System.Runtime.InteropServices;
23 internal class ObjectRegistry : BaseHandle
25 internal ObjectRegistry(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
29 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
31 Interop.ObjectRegistry.DeleteObjectRegistry(swigCPtr);
34 public class ObjectCreatedEventArgs : EventArgs
36 private BaseHandle baseHandle;
38 public BaseHandle BaseHandle
51 public class ObjectDestroyedEventArgs : EventArgs
53 private RefObject refObject;
55 public RefObject RefObject
68 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
69 private delegate void ObjectCreatedEventCallbackDelegate(IntPtr baseHandle);
70 private DaliEventHandler<object, ObjectCreatedEventArgs> objectRegistryObjectCreatedEventHandler;
71 private ObjectCreatedEventCallbackDelegate objectRegistryObjectCreatedEventCallbackDelegate;
73 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
74 private delegate void ObjectDestroyedEventCallbackDelegate(IntPtr fefObject);
75 private DaliEventHandler<object, ObjectDestroyedEventArgs> objectRegistryObjectDestroyedEventHandler;
76 private ObjectDestroyedEventCallbackDelegate objectRegistryObjectDestroyedEventCallbackDelegate;
78 public event DaliEventHandler<object, ObjectCreatedEventArgs> ObjectCreated
82 // Restricted to only one listener
83 if (objectRegistryObjectCreatedEventHandler == null)
85 objectRegistryObjectCreatedEventHandler += value;
87 objectRegistryObjectCreatedEventCallbackDelegate = new ObjectCreatedEventCallbackDelegate(OnObjectCreated);
88 this.ObjectCreatedSignal().Connect(objectRegistryObjectCreatedEventCallbackDelegate);
94 if (objectRegistryObjectCreatedEventHandler != null)
96 this.ObjectCreatedSignal().Disconnect(objectRegistryObjectCreatedEventCallbackDelegate);
99 objectRegistryObjectCreatedEventHandler -= value;
103 // Callback for ObjectRegistry ObjectCreatedSignal
104 private void OnObjectCreated(IntPtr baseHandle)
106 ObjectCreatedEventArgs e = new ObjectCreatedEventArgs();
108 // Populate all members of "e" (ObjectCreatedEventArgs) with real data
109 //e.BaseHandle = BaseHandle.GetBaseHandleFromPtr(baseHandle); //GetBaseHandleFromPtr() is not present in BaseHandle.cs. Not sure what is the reason?
111 if (objectRegistryObjectCreatedEventHandler != null)
113 //here we send all data to user event handlers
114 objectRegistryObjectCreatedEventHandler(this, e);
118 public event DaliEventHandler<object, ObjectDestroyedEventArgs> ObjectDestroyed
122 // Restricted to only one listener
123 if (objectRegistryObjectDestroyedEventHandler == null)
125 objectRegistryObjectDestroyedEventHandler += value;
127 objectRegistryObjectDestroyedEventCallbackDelegate = new ObjectDestroyedEventCallbackDelegate(OnObjectDestroyed);
128 this.ObjectDestroyedSignal().Connect(objectRegistryObjectDestroyedEventCallbackDelegate);
134 if (objectRegistryObjectDestroyedEventHandler != null)
136 this.ObjectDestroyedSignal().Disconnect(objectRegistryObjectDestroyedEventCallbackDelegate);
139 objectRegistryObjectDestroyedEventHandler -= value;
143 // Callback for ObjectRegistry ObjectDestroyedSignal
144 private void OnObjectDestroyed(IntPtr refObject)
146 ObjectDestroyedEventArgs e = new ObjectDestroyedEventArgs();
148 // Populate all members of "e" (ObjectDestroyedEventArgs) with real data
149 e.RefObject = RefObject.GetRefObjectFromPtr(refObject);
151 if (objectRegistryObjectDestroyedEventHandler != null)
153 //here we send all data to user event handlers
154 objectRegistryObjectDestroyedEventHandler(this, e);
159 public ObjectRegistry() : this(Interop.ObjectRegistry.NewObjectRegistry(), true)
161 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
164 public ObjectRegistry(ObjectRegistry handle) : this(Interop.ObjectRegistry.NewObjectRegistry(ObjectRegistry.getCPtr(handle)), true)
166 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
169 public ObjectRegistry Assign(ObjectRegistry rhs)
171 ObjectRegistry ret = new ObjectRegistry(Interop.ObjectRegistry.Assign(SwigCPtr, ObjectRegistry.getCPtr(rhs)), false);
172 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
176 public ObjectCreatedSignal ObjectCreatedSignal()
178 ObjectCreatedSignal ret = new ObjectCreatedSignal(Interop.ObjectRegistry.ObjectCreatedSignal(SwigCPtr), false);
179 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
183 public ObjectDestroyedSignal ObjectDestroyedSignal()
185 ObjectDestroyedSignal ret = new ObjectDestroyedSignal(Interop.ObjectRegistry.ObjectDestroyedSignal(SwigCPtr), false);
186 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();