Follow formatting NUI
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / ObjectRegistry.cs
1 /*
2  * Copyright(c) 2017 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17 using System;
18 using System.Runtime.InteropServices;
19
20 namespace Tizen.NUI
21 {
22     internal class ObjectRegistry : BaseHandle
23     {
24
25         internal ObjectRegistry(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.ObjectRegistry.ObjectRegistry_SWIGUpcast(cPtr), cMemoryOwn)
26         {
27         }
28
29         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(ObjectRegistry obj)
30         {
31             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
32         }
33
34         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
35         {
36             Interop.ObjectRegistry.delete_ObjectRegistry(swigCPtr);
37         }
38
39         /// <since_tizen> 3 </since_tizen>
40         public class ObjectCreatedEventArgs : EventArgs
41         {
42             private BaseHandle _baseHandle;
43
44             /// <since_tizen> 3 </since_tizen>
45             public BaseHandle BaseHandle
46             {
47                 get
48                 {
49                     return _baseHandle;
50                 }
51                 set
52                 {
53                     _baseHandle = value;
54                 }
55             }
56         }
57
58         /// <since_tizen> 3 </since_tizen>
59         public class ObjectDestroyedEventArgs : EventArgs
60         {
61             private RefObject _refObject;
62
63             /// <since_tizen> 3 </since_tizen>
64             public RefObject RefObject
65             {
66                 get
67                 {
68                     return _refObject;
69                 }
70                 set
71                 {
72                     _refObject = value;
73                 }
74             }
75         }
76
77         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
78         private delegate void ObjectCreatedEventCallbackDelegate(IntPtr baseHandle);
79         private DaliEventHandler<object, ObjectCreatedEventArgs> _objectRegistryObjectCreatedEventHandler;
80         private ObjectCreatedEventCallbackDelegate _objectRegistryObjectCreatedEventCallbackDelegate;
81
82         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
83         private delegate void ObjectDestroyedEventCallbackDelegate(IntPtr fefObject);
84         private DaliEventHandler<object, ObjectDestroyedEventArgs> _objectRegistryObjectDestroyedEventHandler;
85         private ObjectDestroyedEventCallbackDelegate _objectRegistryObjectDestroyedEventCallbackDelegate;
86
87         public event DaliEventHandler<object, ObjectCreatedEventArgs> ObjectCreated
88         {
89             add
90             {
91                 lock (this)
92                 {
93                     // Restricted to only one listener
94                     if (_objectRegistryObjectCreatedEventHandler == null)
95                     {
96                         _objectRegistryObjectCreatedEventHandler += value;
97
98                         _objectRegistryObjectCreatedEventCallbackDelegate = new ObjectCreatedEventCallbackDelegate(OnObjectCreated);
99                         this.ObjectCreatedSignal().Connect(_objectRegistryObjectCreatedEventCallbackDelegate);
100                     }
101                 }
102             }
103
104             remove
105             {
106                 lock (this)
107                 {
108                     if (_objectRegistryObjectCreatedEventHandler != null)
109                     {
110                         this.ObjectCreatedSignal().Disconnect(_objectRegistryObjectCreatedEventCallbackDelegate);
111                     }
112
113                     _objectRegistryObjectCreatedEventHandler -= value;
114                 }
115             }
116         }
117
118         // Callback for ObjectRegistry ObjectCreatedSignal
119         private void OnObjectCreated(IntPtr baseHandle)
120         {
121             ObjectCreatedEventArgs e = new ObjectCreatedEventArgs();
122
123             // Populate all members of "e" (ObjectCreatedEventArgs) with real data
124             //e.BaseHandle = BaseHandle.GetBaseHandleFromPtr(baseHandle); //GetBaseHandleFromPtr() is not present in BaseHandle.cs. Not sure what is the reason?
125
126             if (_objectRegistryObjectCreatedEventHandler != null)
127             {
128                 //here we send all data to user event handlers
129                 _objectRegistryObjectCreatedEventHandler(this, e);
130             }
131         }
132
133         public event DaliEventHandler<object, ObjectDestroyedEventArgs> ObjectDestroyed
134         {
135             add
136             {
137                 lock (this)
138                 {
139                     // Restricted to only one listener
140                     if (_objectRegistryObjectDestroyedEventHandler == null)
141                     {
142                         _objectRegistryObjectDestroyedEventHandler += value;
143
144                         _objectRegistryObjectDestroyedEventCallbackDelegate = new ObjectDestroyedEventCallbackDelegate(OnObjectDestroyed);
145                         this.ObjectDestroyedSignal().Connect(_objectRegistryObjectDestroyedEventCallbackDelegate);
146                     }
147                 }
148             }
149
150             remove
151             {
152                 lock (this)
153                 {
154                     if (_objectRegistryObjectDestroyedEventHandler != null)
155                     {
156                         this.ObjectDestroyedSignal().Disconnect(_objectRegistryObjectDestroyedEventCallbackDelegate);
157                     }
158
159                     _objectRegistryObjectDestroyedEventHandler -= value;
160                 }
161             }
162         }
163
164         // Callback for ObjectRegistry ObjectDestroyedSignal
165         private void OnObjectDestroyed(IntPtr refObject)
166         {
167             ObjectDestroyedEventArgs e = new ObjectDestroyedEventArgs();
168
169             // Populate all members of "e" (ObjectDestroyedEventArgs) with real data
170             e.RefObject = RefObject.GetRefObjectFromPtr(refObject);
171
172             if (_objectRegistryObjectDestroyedEventHandler != null)
173             {
174                 //here we send all data to user event handlers
175                 _objectRegistryObjectDestroyedEventHandler(this, e);
176             }
177         }
178
179
180         public ObjectRegistry() : this(Interop.ObjectRegistry.new_ObjectRegistry__SWIG_0(), true)
181         {
182             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
183         }
184
185         public ObjectRegistry(ObjectRegistry handle) : this(Interop.ObjectRegistry.new_ObjectRegistry__SWIG_1(ObjectRegistry.getCPtr(handle)), true)
186         {
187             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
188         }
189
190         public ObjectRegistry Assign(ObjectRegistry rhs)
191         {
192             ObjectRegistry ret = new ObjectRegistry(Interop.ObjectRegistry.ObjectRegistry_Assign(swigCPtr, ObjectRegistry.getCPtr(rhs)), false);
193             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
194             return ret;
195         }
196
197         public ObjectCreatedSignal ObjectCreatedSignal()
198         {
199             ObjectCreatedSignal ret = new ObjectCreatedSignal(Interop.ObjectRegistry.ObjectRegistry_ObjectCreatedSignal(swigCPtr), false);
200             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
201             return ret;
202         }
203
204         public ObjectDestroyedSignal ObjectDestroyedSignal()
205         {
206             ObjectDestroyedSignal ret = new ObjectDestroyedSignal(Interop.ObjectRegistry.ObjectRegistry_ObjectDestroyedSignal(swigCPtr), false);
207             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
208             return ret;
209         }
210     }
211 }