From b177573b7d2df3e088dfe773eed2346f513c110f Mon Sep 17 00:00:00 2001 From: Ickhee Woo Date: Thu, 21 Dec 2017 21:16:29 +0900 Subject: [PATCH] fixed code for the case of calling register many times Change-Id: I58a20f5531c56702acbcae247969213420d248bd Signed-off-by: Ickhee Woo --- .../Tizen.Messaging.Push/PushImpl.cs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Tizen.Messaging.Push/Tizen.Messaging.Push/PushImpl.cs b/src/Tizen.Messaging.Push/Tizen.Messaging.Push/PushImpl.cs index 35a5b37..8342b7a 100644 --- a/src/Tizen.Messaging.Push/Tizen.Messaging.Push/PushImpl.cs +++ b/src/Tizen.Messaging.Push/Tizen.Messaging.Push/PushImpl.cs @@ -26,8 +26,8 @@ namespace Tizen.Messaging.Push { private static readonly object _lock = new object(); private static PushImpl _instance; - private Interop.PushClient.VoidResultCallback registerResult; - private Interop.PushClient.VoidResultCallback unregisterResult; + private static Interop.PushClient.VoidResultCallback registerResult = null; + private static Interop.PushClient.VoidResultCallback unregisterResult = null; internal static PushImpl Instance { @@ -157,6 +157,12 @@ namespace Tizen.Messaging.Push { Log.Info(Interop.PushClient.LogTag, "Register Called"); var task = new TaskCompletionSource(); + if (registerResult != null) + { + Log.Error(Interop.PushClient.LogTag, "Register callback was already registered with same callback"); + return await task.Task; + } + registerResult = (Interop.PushClient.Result regResult, IntPtr msgPtr, IntPtr userData) => { Log.Info(Interop.PushClient.LogTag, "Register Callback Called with " + regResult); @@ -172,6 +178,11 @@ namespace Tizen.Messaging.Push { Log.Error(Interop.PushClient.LogTag, "Unable to set the Result for register"); } + lock (_lock) + { + Log.Error(Interop.PushClient.LogTag, "resigterResult is unset"); + registerResult = null; + } }; Interop.PushClient.ServiceError result = Interop.PushClient.ServiceRegister(_connection, registerResult, IntPtr.Zero); Log.Info(Interop.PushClient.LogTag, "Interop.PushClient.ServiceRegister Completed"); @@ -179,6 +190,11 @@ namespace Tizen.Messaging.Push { Log.Error(Interop.PushClient.LogTag, "Register failed with " + result); task.SetException(PushExceptionFactory.CreateResponseException(result)); + lock (_lock) + { + Log.Error(Interop.PushClient.LogTag, "resigterResult is unset (failed)"); + registerResult = null; + } } return await task.Task; } -- 2.7.4