/* * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; using System.Threading.Tasks; namespace Tizen.Messaging.Push { /// /// The PushClient API provides functions to connect to push service for receiving push messages. /// /// 3 /// /// The PushClient API provides the way to connect with the push service. /// It provides APIs to connect/disconnect from the push service. /// APIs are provided so that an application can register itself /// with the push server along with APIs to request push message. /// public static class PushClient { /// /// Event Handler for receiving the notifications. /// /// 3 public static event EventHandler NotificationReceived { add { lock (_lock) { _notificationReceived += value; } } remove { lock (_lock) { _notificationReceived -= value; } } } /// /// Event Handler for receiving changes in States of the connection. /// /// 3 public static event EventHandler StateChanged { add { lock (_lock) { _stateChanged += value; } } remove { lock (_lock) { _stateChanged -= value; } } } /// /// API to connect with the push service. /// /// 3 /// http://tizen.org/privilege/push /// In case of privilege not defined. /// The Push Application ID Registered with the server. public static void PushServiceConnect(string pushAppId) { PushImpl.PushServiceConnect(pushAppId); } /// /// API to disconnect from the push service. /// /// 3 public static void PushServiceDisconnect() { PushImpl.PushServiceDisconnect(); //PushImpl.Reset(); } /// /// API to Register the application with the push server. /// /// 3 /// /// The method returns a task, which on completion will give a ServerResponse Object. /// public static Task PushServerRegister() { return PushImpl.PushServerRegister(); } /// /// API to Deregister the application from the push server. /// /// 3 /// /// The method returns a task, which on completion will give a ServerResponse Object. /// public static Task PushServerUnregister() { return PushImpl.PushServerUnregister(); } /// /// Gets the unread notifications for the application. /// /// 3 public static void GetUnreadNotifications() { PushImpl.GetUnreadNotifications(); } /// /// registration ID received from server. /// /// 3 /// /// It is the string, which is the ID received from the server. /// public static string GetRegistrationId() { return PushImpl.GetRegistrationId(); } internal static void StateChange(PushConnectionStateEventArgs args) { if (_stateChanged != null) _stateChanged(null, args); } internal static void Notify(PushMessageEventArgs args) { if (_notificationReceived != null) _notificationReceived(null, args); } private static object _lock = new object(); private static event EventHandler _notificationReceived; private static event EventHandler _stateChanged; } }