Debian Codegraph @

Xpjproject/pjsip-apps/src/pjsua/winrt/gui/uwp/VoipTasks/AppService.cs

raw symbols SCIP
1 //*********************************************************
2 //
3 // Copyright (c) Microsoft. All rights reserved.
4 // This code is licensed under the MIT License (MIT).
5 // THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
6 // ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
7 // IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
8 // PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
9 //
10 //*********************************************************
11 using System;
12 using VoipTasks.BackgroundOperations;
13 using VoipTasks.Helpers;
14 using Windows.ApplicationModel.AppService;
15 using Windows.ApplicationModel.Background;
16 using Windows.ApplicationModel.Calls;
17 using Windows.Foundation.Collections;
18 using VoipBackEnd;
19
20 namespace VoipTasks
21 {
22 public sealed class AppService : IBackgroundTask
23 {
24 AppServiceConnection _connection;
25 BackgroundTaskDeferral _deferral;
26
27 public void Run(IBackgroundTaskInstance taskInstance)
28 {
29 AppServiceTriggerDetails triggerDetail = taskInstance.TriggerDetails as AppServiceTriggerDetails;
30 _deferral = taskInstance.GetDeferral();
31
32 // Register for Task Cancel callback
33 taskInstance.Canceled += TaskInstance_Canceled;
34
35 AppServiceConnection connection = triggerDetail.AppServiceConnection;
36 _connection = connection;
37
38 connection.RequestReceived += Connection_RequestReceived;
39 Current.AppConnection = connection;
40 }
41
42 private async void Connection_RequestReceived(AppServiceConnection sender, AppServiceRequestReceivedEventArgs args)
43 {
44 var deferral = args.GetDeferral();
45 var response = new ValueSet();
46 bool stop = false;
47 try
48 {
49 var request = args.Request;
50 var message = request.Message;
51 if (message.ContainsKey(BackgroundOperation.NewBackgroundRequest))
52 {
53 switch ((BackgroundRequest)message[BackgroundOperation.NewBackgroundRequest])
54 {
55 case BackgroundRequest.NewOutgoingCall:
56 Current.AppRequest = args.Request;
57 Current.Request = BackgroundRequest.NewOutgoingCall;
58 Current.AppRequestDeferal = deferral;
59 await Current.RequestNewCallAsync(message[NewCallArguments.DstURI.ToString()] as String);
60 break;
61
62 case BackgroundRequest.EndCall:
63 Current.AppRequest = args.Request;
64 Current.Request = BackgroundRequest.EndCall;
65 Current.AppRequestDeferal = deferral;
66 Current.EndCallAsync();
67 break;
68
69 case BackgroundRequest.StartService:
70 Current.AppRequest = args.Request;
71 Current.Request = BackgroundRequest.StartService;
72 Current.AppRequestDeferal = deferral;
73 Current.StartService();
74
75 break;
76 case BackgroundRequest.StopService:
77 Current.AppRequest = args.Request;
78 Current.Request = BackgroundRequest.StopService;
79 Current.AppRequestDeferal = deferral;
80 Current.StopService();
81 break;
82
83 case BackgroundRequest.GetAccountInfo:
84 Current.AppRequest = args.Request;
85 Current.Request = BackgroundRequest.GetAccountInfo;
86 Current.AppRequestDeferal = deferral;
87
88 Current.GetAccountInfo();
89 break;
90
91 case BackgroundRequest.ModifyAccount:
92 Current.AppRequest = args.Request;
93 Current.Request = BackgroundRequest.ModifyAccount;
94 Current.AppRequestDeferal = deferral;
95 Current.ModifyAccount(message[ModifyAccountArguments.id.ToString()] as String,
96 message[ModifyAccountArguments.registrar.ToString()] as String,
97 message[ModifyAccountArguments.proxy.ToString()] as String,
98 message[ModifyAccountArguments.username.ToString()] as String,
99 message[ModifyAccountArguments.password.ToString()] as String);
100
101 break;
102
103 default:
104 stop = true;
105 break;
106 }
107 }
108 }
109 finally
110 {
111
112 if (stop)
113 {
114 _deferral.Complete();
115 }
116 }
117 }
118
119 private void TaskInstance_Canceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason)
120 {
121 if (_deferral != null)
122 {
123 _deferral.Complete();
124 }
125 }
126
127 private static void Call_ResumeRequested(VoipPhoneCall sender, CallStateChangeEventArgs args)
128 {
129 sender.NotifyCallActive();
130 }
131
132 private static void Call_RejectRequested(VoipPhoneCall sender, CallRejectEventArgs args)
133 {
134 sender.NotifyCallEnded();
135 }
136
137 private static void Call_HoldRequested(VoipPhoneCall sender, CallStateChangeEventArgs args)
138 {
139 sender.NotifyCallHeld();
140 }
141
142 private static void Call_EndRequested(VoipPhoneCall sender, CallStateChangeEventArgs args)
143 {
144 sender.NotifyCallEnded();
145 }
146
147 private static void Call_AnswerRequested(VoipPhoneCall sender, CallAnswerEventArgs args)
148 {
149 sender.NotifyCallActive();
150 }
151 }
152 }