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.
26 /// The PushClient API provides the way to connect with the push service.
27 /// It provides api's to connect/disconnect from the push service.
28 /// Api's are provided so that an application can register itself
29 /// with the push server along with api's to request push message.
33 /// public class Program
35 /// static void Main(string[] args)
37 /// PushClient.PushServiceConnect("xxxxx");
38 /// Task<ServerResponse> tr = PushClient.PushServerRegister();
39 /// tr.GetAwaiter().OnCompleted(() => {
40 /// ServerResponse res = tr.Result;
41 /// PushClient.GetUnreadNotifications();
42 /// Task<ServerResponse> tu = PushClient.PushServerUnregister();
43 /// tu.GetAwaiter().OnCompleted(() => {
44 /// PushClient.PushServiceDisconnect();
47 /// PushClient.NotificationReceived += EventHandlerNotificationReceived;
48 /// PushClient.StateChanged += EventHandlerStateChanged;
51 /// static void EventHandlerNotificationReceived(object sender, PushMessageEventArgs e)
55 /// static void EventHandlerStateChanged(object sender, PushConnectionStateEventArgs e)
61 public static class PushClient
64 /// Event Handler for receiving the notifications.
66 public static event EventHandler<PushMessageEventArgs> NotificationReceived
72 _notificationReceived += value;
79 _notificationReceived -= value;
85 /// Event Handler for receiving changes in States of the connection.
87 public static event EventHandler<PushConnectionStateEventArgs> StateChanged
93 _stateChanged += value;
100 _stateChanged -= value;
106 /// API to connect with the push service.
108 /// <param name="pushAppId"> The Push Application Id Registered with the server.</param>
109 public static void PushServiceConnect(string pushAppId)
111 PushImpl.Instance.PushServiceConnect(pushAppId);
115 /// API to disconnect from the push service.
117 public static void PushServiceDisconnect()
119 PushImpl.Instance.PushServiceDisconnect();
125 /// API to Register the application with the push server.
128 /// The method returns a task which on completion with give a ServerResponse Object.
130 public static Task<ServerResponse> PushServerRegister()
132 return PushImpl.Instance.PushServerRegister();
136 /// API to Deregister the application from the push server.
139 /// The method returns a task which on completion with give a ServerResponse Object.
141 public static Task<ServerResponse> PushServerUnregister()
143 return PushImpl.Instance.PushServerUnregister();
147 /// Gets the unread notifications for the application.
149 public static void GetUnreadNotifications()
151 PushImpl.Instance.GetUnreadNotifications();
155 /// registration Id received from server. </summary>
157 /// It is the string which is the Id received from the server.
159 public static string GetRegistrationId()
161 return PushImpl.Instance.GetRegistrationId();
164 internal static void StateChange(PushConnectionStateEventArgs args)
166 if (_stateChanged != null)
167 _stateChanged(null, args);
170 internal static void Notify(PushMessageEventArgs args)
172 if (_notificationReceived != null)
173 _notificationReceived(null, args);
176 private static object _lock = new object();
177 private static event EventHandler<PushMessageEventArgs> _notificationReceived;
178 private static event EventHandler<PushConnectionStateEventArgs> _stateChanged;