/
MediaControlCommand.cs
739 lines (651 loc) · 27.4 KB
/
MediaControlCommand.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
/*
* 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 Tizen.Applications;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using NativeClient = Interop.MediaControllerClient;
using NativeServer = Interop.MediaControllerServer;
using NativeClientHandle = Interop.MediaControllerClientHandle;
namespace Tizen.Multimedia.Remoting
{
/// <summary>
/// Provides a means to send command to media control server.
/// </summary>
/// <since_tizen> 5 </since_tizen>
public abstract class Command
{
private string _requestId;
/// <summary>
/// The id for command receiver.
/// </summary>
/// <since_tizen> 5 </since_tizen>
protected string ReceiverId { get; private set; }
/// <summary>
/// Initializes a <see cref="Command"/> base class.
/// </summary>
/// <since_tizen> 5 </since_tizen>
protected Command() { }
/// <summary>
/// Sets the server information.
/// </summary>
/// <param name="receiverId">The receiver Id that receives command.</param>
internal void SetRequestInformation(string receiverId)
{
ReceiverId = receiverId ?? throw new ArgumentNullException(nameof(receiverId));
}
/// <summary>
/// Sets the client information.
/// </summary>
/// <param name="receiverId">The receiver Id that receives response for command.</param>
/// <param name="requestId">The request Id for each command.</param>
internal void SetResponseInformation(string receiverId, string requestId)
{
ReceiverId = receiverId ?? throw new ArgumentNullException(nameof(receiverId));
_requestId = requestId;
if (_requestId == null)
{
Log.Info(GetType().FullName, "request_id is null. Response() should not be called.");
}
}
/// <summary>
/// Indicates if the response is needed.
/// </summary>
/// <remarks>If false, the receiver should not respond to the received command.</remarks>
/// <since_tizen> 12 </since_tizen>
public bool IsResponseNeeded => NeedToResponse;
/// <summary>
/// Indicates if the response is needed.
/// </summary>
/// <remarks>
/// This internal API is retained for backward compatibility but is not recommended for new development.
/// Please use <see cref="IsResponseNeeded"/> instead.<br/>
/// If false, the receiver should not respond to the received command.
/// </remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool NeedToResponse => _requestId != null;
/// <summary>
/// Requests command to server.
/// </summary>
/// <returns>The request id for each command.</returns>
internal abstract string Request(NativeClientHandle clientHandle);
/// <summary>
/// Requests command to client.
/// </summary>
/// <param name="serverHandle"></param>
/// <returns>The request id for each command.</returns>
internal virtual string Request(IntPtr serverHandle) => throw new NotImplementedException();
/// <summary>
/// Represents a method that is called when an response command completes.
/// </summary>
/// <since_tizen> 5 </since_tizen>
protected virtual void OnResponseCompleted() { }
/// <summary>
/// Responds to the clients command.
/// </summary>
/// <param name="serverHandle">The server handle.</param>
/// <param name="result">The result of each command.</param>
/// <param name="bundle">The extra data.</param>
internal void Response(IntPtr serverHandle, int result, Bundle bundle)
{
if (NeedToResponse == false)
{
throw new InvalidOperationException("The receiver should not call this, if NeedToResponse is false.");
}
try
{
if (bundle != null)
{
NativeServer.SendCommandReplyBundle(serverHandle, ReceiverId, _requestId, result, bundle.SafeBundleHandle)
.ThrowIfError("Failed to response command.");
}
else
{
NativeServer.SendCommandReply(serverHandle, ReceiverId, _requestId, result, IntPtr.Zero)
.ThrowIfError("Failed to response command.");
}
}
catch (ArgumentException)
{
throw new InvalidOperationException("Server is not running");
}
finally
{
OnResponseCompleted();
}
}
/// <summary>
/// Responds to the clients command.
/// </summary>
/// <param name="clientHandle">The client handle.</param>
/// <param name="result">The result of each command.</param>
/// <param name="bundle">The extra data.</param>
internal void Response(NativeClientHandle clientHandle, int result, Bundle bundle)
{
if (NeedToResponse == false)
{
throw new InvalidOperationException("The receiver should not call this, if NeedToResponse is false.");
}
try
{
if (bundle != null)
{
NativeClient.SendCustomEventReplyBundle(clientHandle, ReceiverId, _requestId, result, bundle.SafeBundleHandle)
.ThrowIfError("Failed to response event.");
}
else
{
NativeClient.SendCustomEventReply(clientHandle, ReceiverId, _requestId, result, IntPtr.Zero)
.ThrowIfError("Failed to response event.");
}
}
catch (ArgumentException)
{
throw new InvalidOperationException("Server is not running");
}
finally
{
OnResponseCompleted();
}
}
}
/// <summary>
/// Provides a means to send playback command to media control server.
/// </summary>
public sealed class PlaybackCommand : Command
{
/// <summary>
/// Initializes a new instance of the <see cref="PlaybackCommand"/> class.
/// </summary>
/// <param name="action">A <see cref="MediaControlPlaybackCommand"/>.</param>
/// <exception cref="ArgumentException"><paramref name="action"/> is not valid.</exception>
/// <since_tizen> 5 </since_tizen>
public PlaybackCommand(MediaControlPlaybackCommand action)
{
ValidationUtil.ValidateEnum(typeof(MediaControlPlaybackCommand), action, nameof(action));
Action = action;
}
/// <summary>
/// Gets the playback action.
/// </summary>
/// <since_tizen> 5 </since_tizen>
public MediaControlPlaybackCommand Action { get; }
internal override string Request(NativeClientHandle clientHandle)
{
ValidationUtil.ValidateEnum(typeof(MediaControlPlaybackCommand), Action, nameof(Action));
NativeClient.SendPlaybackActionCommand(clientHandle, ReceiverId, Action.ToNative(), out string requestId)
.ThrowIfError("Failed to send playback command.");
return requestId;
}
}
/// <summary>
/// Provides a means to send playback command to order specific time position.
/// </summary>
public sealed class PlaybackPositionCommand : Command
{
/// <summary>
/// Initializes a new instance of the <see cref="PlaybackPositionCommand"/> class.
/// </summary>
/// <param name="position">The playback position in milliseconds.</param>
/// <since_tizen> 5 </since_tizen>
public PlaybackPositionCommand(ulong position)
{
Position = position;
}
/// <summary>
/// Gets the position to play.
/// </summary>
/// <since_tizen> 5 </since_tizen>
public ulong Position { get; }
internal override string Request(NativeClientHandle clientHandle)
{
NativeClient.SendPlaybackPositionCommand(clientHandle, ReceiverId, Position, out string requestId)
.ThrowIfError("Failed to send playback position command.");
return requestId;
}
}
/// <summary>
/// Provides a means to send playback command with playlist information.
/// </summary>
public sealed class PlaylistCommand : Command
{
/// <summary>
/// Initializes a new instance of the <see cref="PlaybackCommand"/> class.
/// </summary>
/// <param name="action">A <see cref="MediaControlPlaybackCommand"/>.</param>
/// <param name="playlistName">The playlist name of the server.</param>
/// <param name="index">The index of the media in the playlist.</param>
/// <param name="position">The playback position in milliseconds.</param>
/// <exception cref="ArgumentException"><paramref name="action"/>is not valid.</exception>
/// <exception cref="ArgumentNullException">
/// <paramref name="playlistName"/> or <paramref name="index"/> is null.
/// </exception>
/// <since_tizen> 5 </since_tizen>
public PlaylistCommand(MediaControlPlaybackCommand action, string playlistName, string index, ulong position)
{
ValidationUtil.ValidateEnum(typeof(MediaControlPlaybackCommand), action, nameof(action));
Action = action;
Index = index ?? throw new ArgumentNullException(nameof(index));
Name = playlistName ?? throw new ArgumentNullException(nameof(playlistName));
Position = position;
}
/// <summary>
/// Initializes a new instance of the <see cref="PlaybackCommand"/> class.
/// </summary>
/// <param name="action">A <see cref="MediaControlPlaybackCommand"/>.</param>
/// <param name="playlistName">The playlist name of the server.</param>
/// <param name="index">The index of the media in the playlist.</param>
/// <exception cref="ArgumentNullException">
/// <paramref name="playlistName"/> or <paramref name="index"/> is null.
/// </exception>
/// <since_tizen> 5 </since_tizen>
public PlaylistCommand(MediaControlPlaybackCommand action, string playlistName, string index)
: this(action, playlistName, index, 0)
{
}
/// <summary>
/// Gets the playback action.
/// </summary>
/// <since_tizen> 5 </since_tizen>
public MediaControlPlaybackCommand Action { get; }
/// <summary>
/// Gets the position to play.
/// </summary>
/// <since_tizen> 5 </since_tizen>
public ulong Position { get; }
/// <summary>
/// Gets the index of playlist.
/// </summary>
/// <since_tizen> 5 </since_tizen>
public string Index { get; }
/// <summary>
/// Gets the name of playlist.
/// </summary>
/// <since_tizen> 5 </since_tizen>
public string Name { get; }
internal override string Request(NativeClientHandle clientHandle)
{
ValidationUtil.ValidateEnum(typeof(MediaControlPlaybackCommand), Action, nameof(Action));
NativeClient.SendPlaylistCommand(clientHandle, ReceiverId, Name, Index, Action.ToNative(),
Position, out string requestId).ThrowIfError("Failed to send playlist command.");
return requestId;
}
}
/// <summary>
/// Provides a means to to send shuffle mode commands.
/// </summary>
/// <since_tizen> 5 </since_tizen>
public sealed class ShuffleModeCommand : Command
{
/// <summary>
/// Initializes a new instance of the <see cref="ShuffleModeCommand"/> class.
/// </summary>
/// <param name="enabled">A shuffle mode.</param>
/// <since_tizen> 5 </since_tizen>
public ShuffleModeCommand(bool enabled)
{
Enabled = enabled;
}
/// <summary>
/// Gets a value indicating whether the shuffle mode is enabled.
/// </summary>
public bool Enabled { get; }
internal override string Request(NativeClientHandle clientHandle)
{
var mode = Enabled ? MediaControllerNativeShuffleMode.On : MediaControllerNativeShuffleMode.Off;
NativeClient.SendShuffleModeCommand(clientHandle, ReceiverId, mode, out string requestId).
ThrowIfError("Failed to send playback shuffle command.");
return requestId;
}
}
/// <summary>
/// Provides a means to to send repeat mode commands.
/// </summary>
/// <since_tizen> 5 </since_tizen>
public sealed class RepeatModeCommand : Command
{
/// <summary>
/// Initializes a new instance of the <see cref="RepeatModeCommand"/> class.
/// </summary>
/// <param name="mode">The <see cref="MediaControlRepeatMode"/>.</param>
/// <exception cref="ArgumentException"><paramref name="mode"/> is not valid.</exception>
/// <since_tizen> 5 </since_tizen>
public RepeatModeCommand(MediaControlRepeatMode mode)
{
ValidationUtil.ValidateEnum(typeof(MediaControlRepeatMode), mode, nameof(mode));
Mode = mode;
}
/// <summary>
/// Gets the repeat mode.
/// </summary>
/// <since_tizen> 5 </since_tizen>
public MediaControlRepeatMode Mode { get; }
internal override string Request(NativeClientHandle clientHandle)
{
ValidationUtil.ValidateEnum(typeof(MediaControlRepeatMode), Mode, nameof(Mode));
NativeClient.SendRepeatModeCommand(clientHandle, ReceiverId, Mode.ToNative(), out string requestId).
ThrowIfError("Failed to send playback repeat command.");
return requestId;
}
}
/// <summary>
/// Provides a means to to send subtitle mode command.
/// </summary>
/// <since_tizen> 6 </since_tizen>
public sealed class SubtitleModeCommand : Command
{
/// <summary>
/// Initializes a new instance of the <see cref="SubtitleModeCommand"/> class.
/// </summary>
/// <param name="isEnabled">A value indicating whether subtitle mode is enabled.</param>
/// <since_tizen> 6 </since_tizen>
public SubtitleModeCommand(bool isEnabled)
{
IsEnabled = isEnabled;
}
/// <summary>
/// Gets a value indicating whether subtitle mode is enabled or not.
/// </summary>
/// <since_tizen> 6 </since_tizen>
public bool IsEnabled { get; }
internal override string Request(NativeClientHandle clientHandle)
{
NativeClient.SendSubtitleModeCommand(clientHandle, ReceiverId, IsEnabled, out string requestId).
ThrowIfError("Failed to send subtitle mode command.");
return requestId;
}
}
/// <summary>
/// Provides a means to to send 360 mode command.
/// </summary>
/// <since_tizen> 6 </since_tizen>
public sealed class Mode360Command : Command
{
/// <summary>
/// Initializes a new instance of the <see cref="Mode360Command"/> class.
/// </summary>
/// <param name="isEnabled">A value indicating whether 360 mode is enabled or not.</param>
/// <since_tizen> 6 </since_tizen>
public Mode360Command(bool isEnabled)
{
IsEnabled = isEnabled;
}
/// <summary>
/// Gets a value indicating whether 360 mode is enabled or not.
/// </summary>
/// <since_tizen> 6 </since_tizen>
public bool IsEnabled { get; }
internal override string Request(NativeClientHandle clientHandle)
{
NativeClient.SendMode360Command(clientHandle, ReceiverId, IsEnabled, out string requestId).
ThrowIfError("Failed to send 360 mode command.");
return requestId;
}
}
/// <summary>
/// Provides a means to to send display mode command.
/// </summary>
/// <since_tizen> 6 </since_tizen>
public sealed class DisplayModeCommand : Command
{
/// <summary>
/// Initializes a new instance of the <see cref="DisplayModeCommand"/> class.
/// </summary>
/// <param name="mode">The <see cref="MediaControlDisplayMode"/>.</param>
/// <exception cref="ArgumentException"><paramref name="mode"/> is not valid.</exception>
/// <since_tizen> 6 </since_tizen>
public DisplayModeCommand(MediaControlDisplayMode mode)
{
ValidationUtil.ValidateEnum(typeof(MediaControlDisplayMode), mode, nameof(mode));
Mode = mode;
}
/// <summary>
/// Gets the display mode.
/// </summary>
/// <since_tizen> 6 </since_tizen>
public MediaControlDisplayMode Mode { get; }
internal override string Request(NativeClientHandle clientHandle)
{
NativeClient.SendDisplayModeCommand(clientHandle, ReceiverId, Mode.ToNative(), out string requestId).
ThrowIfError("Failed to send display mode command.");
return requestId;
}
}
/// <summary>
/// Provides a means to to send display rotation command.
/// </summary>
/// <since_tizen> 6 </since_tizen>
public sealed class DisplayRotationCommand : Command
{
/// <summary>
/// Initializes a new instance of the <see cref="DisplayRotationCommand"/> class.
/// </summary>
/// <param name="rotation">The <see cref="Rotation"/>.</param>
/// <exception cref="ArgumentException"><paramref name="rotation"/> is not valid.</exception>
/// <since_tizen> 6 </since_tizen>
public DisplayRotationCommand(Rotation rotation)
{
ValidationUtil.ValidateEnum(typeof(Rotation), rotation, nameof(rotation));
Rotation = rotation;
}
/// <summary>
/// Gets the display rotation.
/// </summary>
/// <since_tizen> 6 </since_tizen>
public Rotation Rotation { get; }
internal override string Request(NativeClientHandle clientHandle)
{
NativeClient.SendDisplayRotationCommand(clientHandle, ReceiverId, Rotation.ToNative(), out string requestId).
ThrowIfError("Failed to send display rotation command.");
return requestId;
}
}
/// <summary>
/// Provides a means to to send custom commands.
/// </summary>
/// <remarks>This command can be used by both client and server to send predefined command or data.</remarks>
/// <since_tizen> 5 </since_tizen>
public sealed class CustomCommand : Command
{
/// <summary>
/// Initializes a new instance of the <see cref="CustomCommand"/> class.
/// </summary>
/// <param name="action">A predefined custom command.</param>
/// <since_tizen> 5 </since_tizen>
public CustomCommand(string action)
{
Action = action ?? throw new ArgumentNullException(nameof(action));
}
/// <summary>
/// Initializes a new instance of the <see cref="CustomCommand"/> class.
/// </summary>
/// <param name="action">A predefined custom command.</param>
/// <param name="bundle">The extra data for custom command.</param>
/// <since_tizen> 5 </since_tizen>
public CustomCommand(string action, Bundle bundle)
: this(action)
{
Bundle = bundle;
}
///<summary>
/// Gets the custom action.
/// </summary>
/// <since_tizen> 5 </since_tizen>
public string Action { get; }
/// <summary>
/// Gets the extra data.
/// </summary>
/// <since_tizen> 5 </since_tizen>
public Bundle Bundle { get; }
internal override string Request(NativeClientHandle clientHandle)
{
string requestId = null;
if (Bundle != null)
{
NativeClient.SendCustomCommandBundle(clientHandle, ReceiverId, Action, Bundle.SafeBundleHandle, out requestId).
ThrowIfError("Failed to send custom command.");
}
else
{
NativeClient.SendCustomCommand(clientHandle, ReceiverId, Action, IntPtr.Zero, out requestId).
ThrowIfError("Failed to send custom command.");
}
return requestId;
}
internal override string Request(IntPtr serverHandle)
{
string requestId = null;
if (Bundle != null)
{
NativeServer.SendCustomEventBundle(serverHandle, ReceiverId, Action, Bundle.SafeBundleHandle, out requestId)
.ThrowIfError("Failed to send costom event.");
}
else
{
NativeServer.SendCustomEvent(serverHandle, ReceiverId, Action, IntPtr.Zero, out requestId)
.ThrowIfError("Failed to send costom event.");
}
return requestId;
}
}
/// <summary>
/// Provides a means to to send search commands.
/// </summary>
/// <since_tizen> 5 </since_tizen>
public sealed class SearchCommand : Command
{
private readonly IntPtr _searchHandle;
/// <summary>
/// Initializes a new instance of the <see cref="SearchCommand"/> class.
/// </summary>
/// <remarks>User can search maximum 20 items once.</remarks>
/// <exception cref="ArgumentNullException"><paramref name="conditions"/> is not set.</exception>
/// <exception cref="ArgumentException">
/// <paramref name="conditions.Count"/> is greater than maximum value(20).<br/>
/// -or-<br/>
/// <paramref name="conditions.Count"/> is less than 1.
/// </exception>
/// <exception cref="InvalidOperationException">An internal error occurs.</exception>
/// <param name="conditions">The set of <see cref="MediaControlSearchCondition"/>.</param>
/// <since_tizen> 5 </since_tizen>
public SearchCommand(List<MediaControlSearchCondition> conditions)
{
if (conditions == null)
{
throw new ArgumentNullException(nameof(conditions));
}
if (conditions.Count <= 0 || conditions.Count > 20)
{
var errMessage = $"Invalid number of search conditions. : {conditions.Count}. " +
$"Valid range is 1 ~ 20.";
throw new ArgumentException(errMessage);
}
NativeClient.CreateSearchHandle(out _searchHandle).ThrowIfError("Failed to create search handle.");
try
{
foreach (var condition in conditions)
{
if (condition.Bundle != null)
{
NativeClient.SetSearchConditionBundle(_searchHandle, condition.ContentType, condition.Category,
condition.Keyword, condition.Bundle.SafeBundleHandle).
ThrowIfError("Failed to set search condition.");
}
else
{
NativeClient.SetSearchCondition(_searchHandle, condition.ContentType, condition.Category,
condition.Keyword, IntPtr.Zero).
ThrowIfError("Failed to set search condition.");
}
}
}
catch
{
if (_searchHandle != IntPtr.Zero)
{
NativeClient.DestroySearchHandle(_searchHandle).ThrowIfError("Failed to destroy search handle");
}
throw;
}
}
/// <summary>
/// Initializes a new instance of the <see cref="SearchCommand"/> class.
/// </summary>
/// <exception cref="ArgumentNullException"><paramref name="condition"/> is not set.</exception>
/// <exception cref="InvalidOperationException">An internal error occurs.</exception>
/// <param name="condition">The set of <see cref="MediaControlSearchCondition"/>.</param>
/// <since_tizen> 5 </since_tizen>
public SearchCommand(MediaControlSearchCondition condition)
{
if (condition == null)
{
throw new ArgumentNullException(nameof(condition));
}
NativeClient.CreateSearchHandle(out _searchHandle).ThrowIfError("Failed to create search handle.");
try
{
if (condition.Bundle != null)
{
NativeClient.SetSearchConditionBundle(_searchHandle, condition.ContentType, condition.Category,
condition.Keyword, condition.Bundle.SafeBundleHandle).
ThrowIfError("Failed to set search condition.");
}
else
{
NativeClient.SetSearchCondition(_searchHandle, condition.ContentType, condition.Category,
condition.Keyword, IntPtr.Zero).
ThrowIfError("Failed to set search condition.");
}
}
catch
{
if (_searchHandle != IntPtr.Zero)
{
NativeClient.DestroySearchHandle(_searchHandle).ThrowIfError("Failed to destroy search handle");
}
throw;
}
}
/// <summary>
/// Initializes a new instance of the <see cref="SearchCommand"/> class by server side.
/// </summary>
internal SearchCommand(List<MediaControlSearchCondition> conditions, IntPtr searchHandle)
{
_searchHandle = searchHandle;
Conditions = conditions;
}
/// <summary>
/// Gets or sets the search conditions.
/// </summary>
/// <remarks>This property is used by MediaControlServer.</remarks>
/// <since_tizen> 5 </since_tizen>
public IEnumerable<MediaControlSearchCondition> Conditions { get; private set; }
internal override string Request(NativeClientHandle clientHandle)
{
NativeClient.SendSearchCommand(clientHandle, ReceiverId, _searchHandle, out string requestId).
ThrowIfError("Failed to send search command.");
return requestId;
}
/// <summary>
/// Represents a method that is called when an response command completes.
/// </summary>
/// <since_tizen> 5 </since_tizen>
protected override void OnResponseCompleted()
{
base.OnResponseCompleted();
}
}
}