2 * Copyright(c) 2017 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.
18 using System.Runtime.InteropServices;
22 internal class ObjectRegistry : BaseHandle
25 internal ObjectRegistry(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.ObjectRegistry.Upcast(cPtr), cMemoryOwn)
29 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(ObjectRegistry obj)
31 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.SwigCPtr;
34 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
36 Interop.ObjectRegistry.DeleteObjectRegistry(swigCPtr);
39 public class ObjectCreatedEventArgs : EventArgs
41 private BaseHandle _baseHandle;
43 public BaseHandle BaseHandle
56 public class ObjectDestroyedEventArgs : EventArgs
58 private RefObject _refObject;
60 public RefObject RefObject
73 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
74 private delegate void ObjectCreatedEventCallbackDelegate(IntPtr baseHandle);
75 private DaliEventHandler<object, ObjectCreatedEventArgs> _objectRegistryObjectCreatedEventHandler;
76 private ObjectCreatedEventCallbackDelegate _objectRegistryObjectCreatedEventCallbackDelegate;
78 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
79 private delegate void ObjectDestroyedEventCallbackDelegate(IntPtr fefObject);
80 private DaliEventHandler<object, ObjectDestroyedEventArgs> _objectRegistryObjectDestroyedEventHandler;
81 private ObjectDestroyedEventCallbackDelegate _objectRegistryObjectDestroyedEventCallbackDelegate;
83 public event DaliEventHandler<object, ObjectCreatedEventArgs> ObjectCreated
87 // Restricted to only one listener
88 if (_objectRegistryObjectCreatedEventHandler == null)
90 _objectRegistryObjectCreatedEventHandler += value;
92 _objectRegistryObjectCreatedEventCallbackDelegate = new ObjectCreatedEventCallbackDelegate(OnObjectCreated);
93 this.ObjectCreatedSignal().Connect(_objectRegistryObjectCreatedEventCallbackDelegate);
99 if (_objectRegistryObjectCreatedEventHandler != null)
101 this.ObjectCreatedSignal().Disconnect(_objectRegistryObjectCreatedEventCallbackDelegate);
104 _objectRegistryObjectCreatedEventHandler -= value;
108 // Callback for ObjectRegistry ObjectCreatedSignal
109 private void OnObjectCreated(IntPtr baseHandle)
111 ObjectCreatedEventArgs e = new ObjectCreatedEventArgs();
113 // Populate all members of "e" (ObjectCreatedEventArgs) with real data
114 //e.BaseHandle = BaseHandle.GetBaseHandleFromPtr(baseHandle); //GetBaseHandleFromPtr() is not present in BaseHandle.cs. Not sure what is the reason?
116 if (_objectRegistryObjectCreatedEventHandler != null)
118 //here we send all data to user event handlers
119 _objectRegistryObjectCreatedEventHandler(this, e);
123 public event DaliEventHandler<object, ObjectDestroyedEventArgs> ObjectDestroyed
127 // Restricted to only one listener
128 if (_objectRegistryObjectDestroyedEventHandler == null)
130 _objectRegistryObjectDestroyedEventHandler += value;
132 _objectRegistryObjectDestroyedEventCallbackDelegate = new ObjectDestroyedEventCallbackDelegate(OnObjectDestroyed);
133 this.ObjectDestroyedSignal().Connect(_objectRegistryObjectDestroyedEventCallbackDelegate);
139 if (_objectRegistryObjectDestroyedEventHandler != null)
141 this.ObjectDestroyedSignal().Disconnect(_objectRegistryObjectDestroyedEventCallbackDelegate);
144 _objectRegistryObjectDestroyedEventHandler -= value;
148 // Callback for ObjectRegistry ObjectDestroyedSignal
149 private void OnObjectDestroyed(IntPtr refObject)
151 ObjectDestroyedEventArgs e = new ObjectDestroyedEventArgs();
153 // Populate all members of "e" (ObjectDestroyedEventArgs) with real data
154 e.RefObject = RefObject.GetRefObjectFromPtr(refObject);
156 if (_objectRegistryObjectDestroyedEventHandler != null)
158 //here we send all data to user event handlers
159 _objectRegistryObjectDestroyedEventHandler(this, e);
164 public ObjectRegistry() : this(Interop.ObjectRegistry.NewObjectRegistry(), true)
166 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
169 public ObjectRegistry(ObjectRegistry handle) : this(Interop.ObjectRegistry.NewObjectRegistry(ObjectRegistry.getCPtr(handle)), true)
171 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
174 public ObjectRegistry Assign(ObjectRegistry rhs)
176 ObjectRegistry ret = new ObjectRegistry(Interop.ObjectRegistry.Assign(SwigCPtr, ObjectRegistry.getCPtr(rhs)), false);
177 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
181 public ObjectCreatedSignal ObjectCreatedSignal()
183 ObjectCreatedSignal ret = new ObjectCreatedSignal(Interop.ObjectRegistry.ObjectCreatedSignal(SwigCPtr), false);
184 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
188 public ObjectDestroyedSignal ObjectDestroyedSignal()
190 ObjectDestroyedSignal ret = new ObjectDestroyedSignal(Interop.ObjectRegistry.ObjectDestroyedSignal(SwigCPtr), false);
191 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();