2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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.Threading.Tasks;
20 namespace Tizen.Messaging.Push
23 /// The PushClient API provides functions to connect to push service for receiving push messages.
25 /// <since_tizen> 3 </since_tizen>
27 /// The PushClient API provides the way to connect with the push service.
28 /// It provides APIs to connect/disconnect from the push service.
29 /// APIs are provided so that an application can register itself
30 /// with the push server along with APIs to request push message.
32 public static class PushClient
35 /// Event Handler for receiving the notifications.
37 /// <since_tizen> 3 </since_tizen>
38 public static event EventHandler<PushMessageEventArgs> NotificationReceived
44 _notificationReceived += value;
51 _notificationReceived -= value;
57 /// Event Handler for receiving changes in States of the connection.
59 /// <since_tizen> 3 </since_tizen>
60 public static event EventHandler<PushConnectionStateEventArgs> StateChanged
66 _stateChanged += value;
73 _stateChanged -= value;
79 /// API to connect with the push service.
81 /// <since_tizen> 3 </since_tizen>
82 /// <privilege>http://tizen.org/privilege/push</privilege>
83 /// <exception cref="InvalidOperationException"> In case of privilege not defined. </exception>
84 /// <param name="pushAppId"> The Push Application ID Registered with the server.</param>
85 public static void PushServiceConnect(string pushAppId)
87 PushImpl.Instance.PushServiceConnect(pushAppId);
91 /// API to disconnect from the push service.
93 /// <since_tizen> 3 </since_tizen>
94 public static void PushServiceDisconnect()
96 PushImpl.Instance.PushServiceDisconnect();
102 /// API to Register the application with the push server.
104 /// <since_tizen> 3 </since_tizen>
106 /// The method returns a task, which on completion will give a ServerResponse Object.
108 public static Task<ServerResponse> PushServerRegister()
110 return PushImpl.Instance.PushServerRegister();
114 /// API to Deregister the application from the push server.
116 /// <since_tizen> 3 </since_tizen>
118 /// The method returns a task, which on completion will give a ServerResponse Object.
120 public static Task<ServerResponse> PushServerUnregister()
122 return PushImpl.Instance.PushServerUnregister();
126 /// Gets the unread notifications for the application.
128 /// <since_tizen> 3 </since_tizen>
129 public static void GetUnreadNotifications()
131 PushImpl.Instance.GetUnreadNotifications();
135 /// registration ID received from server.
137 /// <since_tizen> 3 </since_tizen>
139 /// It is the string, which is the ID received from the server.
141 public static string GetRegistrationId()
143 return PushImpl.Instance.GetRegistrationId();
146 internal static void StateChange(PushConnectionStateEventArgs args)
148 if (_stateChanged != null)
149 _stateChanged(null, args);
152 internal static void Notify(PushMessageEventArgs args)
154 if (_notificationReceived != null)
155 _notificationReceived(null, args);
158 private static object _lock = new object();
159 private static event EventHandler<PushMessageEventArgs> _notificationReceived;
160 private static event EventHandler<PushConnectionStateEventArgs> _stateChanged;