From: Younho Park Date: Mon, 12 Feb 2018 04:55:08 +0000 (+0900) Subject: [Push] Fixed delegator reference holding issue (state cb, noti cb, register result... X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2e705826474d0b33fe1787183075cf83c43c2c63;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [Push] Fixed delegator reference holding issue (state cb, noti cb, register result cb, unregister result cb) Change-Id: Iefad85814d39ada0de340762007f618a708ff237 Signed-off-by: Younho Park --- diff --git a/src/Tizen.Messaging.Push/Tizen.Messaging.Push/PushImpl.cs b/src/Tizen.Messaging.Push/Tizen.Messaging.Push/PushImpl.cs index 8676c0a87..40c6bfd7f 100644 --- a/src/Tizen.Messaging.Push/Tizen.Messaging.Push/PushImpl.cs +++ b/src/Tizen.Messaging.Push/Tizen.Messaging.Push/PushImpl.cs @@ -26,6 +26,8 @@ namespace Tizen.Messaging.Push { private static readonly object _lock = new object(); private static PushImpl _instance; + private static Interop.PushClient.VoidStateChangedCallback stateDelegate = null; + private static Interop.PushClient.VoidNotifyCallback notifyDelegate = null; private static Interop.PushClient.VoidResultCallback registerResult = null; private static Interop.PushClient.VoidResultCallback unregisterResult = null; @@ -54,7 +56,7 @@ namespace Tizen.Messaging.Push internal void PushServiceConnect(string pushAppId) { - Interop.PushClient.VoidStateChangedCallback stateDelegate = (int state, string err, IntPtr userData) => + stateDelegate = (int state, string err, IntPtr userData) => { if (err == null) { @@ -63,7 +65,7 @@ namespace Tizen.Messaging.Push PushConnectionStateEventArgs args = new PushConnectionStateEventArgs((PushConnectionStateEventArgs.PushState)state, err); PushClient.StateChange(args); }; - Interop.PushClient.VoidNotifyCallback notifyDelegate = (IntPtr notification, IntPtr userData) => + notifyDelegate = (IntPtr notification, IntPtr userData) => { Interop.PushClient.ServiceError result; PushMessageEventArgs ob = new PushMessageEventArgs(); @@ -160,23 +162,33 @@ namespace Tizen.Messaging.Push if (registerResult != null) { Log.Error(Interop.PushClient.LogTag, "Register callback was already registered with same callback"); + task.SetException(PushExceptionFactory.CreateResponseException(Interop.PushClient.ServiceError.OpearationFailed)); return await task.Task; } registerResult = (Interop.PushClient.Result regResult, IntPtr msgPtr, IntPtr userData) => { Log.Info(Interop.PushClient.LogTag, "Register Callback Called with " + regResult); - string msg = ""; - if (msgPtr != IntPtr.Zero) + + if (regResult < Interop.PushClient.Result.Success || regResult > Interop.PushClient.Result.SystemError) { - msg = Marshal.PtrToStringAnsi(msgPtr); + Log.Error(Interop.PushClient.LogTag, "registerResult is called but has wrong resResult value"); + task.SetException(PushExceptionFactory.CreateResponseException(Interop.PushClient.ServiceError.OpearationFailed)); } - ServerResponse response = new ServerResponse(); - response.ServerResult = (ServerResponse.Result)regResult; - response.ServerMessage = msg; - if (task.TrySetResult(response) == false) + else { - Log.Error(Interop.PushClient.LogTag, "Unable to set the Result for register"); + string msg = ""; + if (msgPtr != IntPtr.Zero) + { + msg = Marshal.PtrToStringAnsi(msgPtr); + } + ServerResponse response = new ServerResponse(); + response.ServerResult = (ServerResponse.Result)regResult; + response.ServerMessage = msg; + if (task.TrySetResult(response) == false) + { + Log.Error(Interop.PushClient.LogTag, "Unable to set the Result for register"); + } } lock (_lock) { @@ -204,18 +216,27 @@ namespace Tizen.Messaging.Push var task = new TaskCompletionSource(); unregisterResult = (Interop.PushClient.Result regResult, IntPtr msgPtr, IntPtr userData) => { - Log.Info(Interop.PushClient.LogTag, "Unregister Callback Called"); - string msg = ""; - if (msgPtr != IntPtr.Zero) + Log.Info(Interop.PushClient.LogTag, "Unregister Callback Called with " + regResult); + + if (regResult < Interop.PushClient.Result.Success || regResult > Interop.PushClient.Result.SystemError) { - msg = Marshal.PtrToStringAnsi(msgPtr); + Log.Error(Interop.PushClient.LogTag, "unregisterResult is called but has wrong resResult value"); + task.SetException(PushExceptionFactory.CreateResponseException(Interop.PushClient.ServiceError.OpearationFailed)); } - ServerResponse response = new ServerResponse(); - response.ServerResult = (ServerResponse.Result)regResult; - response.ServerMessage = msg; - if (task.TrySetResult(response) == false) + else { - Log.Error(Interop.PushClient.LogTag, "Unable to set the Result for Unregister"); + string msg = ""; + if (msgPtr != IntPtr.Zero) + { + msg = Marshal.PtrToStringAnsi(msgPtr); + } + ServerResponse response = new ServerResponse(); + response.ServerResult = (ServerResponse.Result)regResult; + response.ServerMessage = msg; + if (task.TrySetResult(response) == false) + { + Log.Error(Interop.PushClient.LogTag, "Unable to set the Result for Unregister"); + } } }; Interop.PushClient.ServiceError result = Interop.PushClient.ServiceDeregister(_connection, unregisterResult, IntPtr.Zero);