Merge remote-tracking branch 'github/API4' into tizen_4.0
authorDotnetBuild <dotnetbuild.tizen@gmail.com>
Fri, 19 Jan 2018 02:51:49 +0000 (11:51 +0900)
committerDotnetBuild <dotnetbuild.tizen@gmail.com>
Fri, 19 Jan 2018 02:51:49 +0000 (11:51 +0900)
1  2 
src/Tizen.Messaging.Push/Tizen.Messaging.Push/PushImpl.cs

@@@ -26,8 -26,8 +26,8 @@@ namespace Tizen.Messaging.Pus
      {
          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
          {
@@@ -40,8 -40,8 +40,8 @@@
                          Log.Info(Interop.PushClient.LogTag, "Creating New Instance");
                          _instance = new PushImpl();
                      }
+                     return _instance;
                  }
-                 return _instance;
              }
          }
  
          {
              Log.Info(Interop.PushClient.LogTag, "Register Called");
              var task = new TaskCompletionSource<ServerResponse>();
 +            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);
                  {
                      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");
              {
                  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;
          }