-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
APClientCommunication.cpp
2680 lines (2200 loc) · 89.8 KB
/
APClientCommunication.cpp
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
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/******************************************************************************/
/* APlayer client communication class. */
/******************************************************************************/
/* This source, or parts thereof, may be used in any software as long the */
/* license of APlayer is keep. See the LICENSE file for more information. */
/* */
/* Copyright (C) 1998-2002 by The APlayer-Team. */
/* All rights reserved. */
/******************************************************************************/
// PolyKit headers
#include "POS.h"
#include "PDebug.h"
#include "PException.h"
#include "PSystem.h"
// APlayerKit headers
#include "APGlobal.h"
#include "APClientCommunication.h"
// Server headers
#include "APApplication.h"
#include "APPlayer.h"
#include "APAddOnWindows.h"
#include "APClientCommunication.h"
#include "ResourceIDs.h"
/******************************************************************************/
/* Global variables */
/******************************************************************************/
extern APGlobal *globalData;
/******************************************************************************/
/* Constructor */
/******************************************************************************/
APClientCommunication::APClientCommunication(void) : BLooper("Server client add-on looper")
{
// Add all the commands to the list
cmdList.InsertItem("AddFile", AddFile);
cmdList.InsertItem("CanChangePosition", CanChangePosition);
cmdList.InsertItem("ChangeChannels", ChangeChannels);
cmdList.InsertItem("DisableAddOn", DisableAddOn);
cmdList.InsertItem("EnableAddOn", EnableAddOn);
cmdList.InsertItem("EndPlayer", EndPlayer);
cmdList.InsertItem("GetAuthor", GetAuthor);
cmdList.InsertItem("GetCurrentSong", GetCurrentSong);
cmdList.InsertItem("GetMaxSongNumber", GetMaxSongNumber);
cmdList.InsertItem("GetModuleChannels", GetModuleChannels);
cmdList.InsertItem("GetModuleFormat", GetModuleFormat);
cmdList.InsertItem("GetModuleInformation", GetModuleInformation);
cmdList.InsertItem("GetModuleName", GetModuleName);
cmdList.InsertItem("GetModuleSize", GetModuleSize);
cmdList.InsertItem("GetPlayerName", GetPlayerName);
cmdList.InsertItem("GetSongLength", GetSongLength);
cmdList.InsertItem("GetSongPosition", GetSongPosition);
cmdList.InsertItem("GetTimeList", GetTimeList);
cmdList.InsertItem("GetTotalTime", GetTotalTime);
cmdList.InsertItem("HoldPlaying", HoldPlaying);
cmdList.InsertItem("InitPlayer", InitPlayer);
cmdList.InsertItem("LoadFile", LoadFile);
cmdList.InsertItem("OpenConfigWindow", OpenConfigWindow);
cmdList.InsertItem("OpenDisplayWindow", OpenDisplayWindow);
cmdList.InsertItem("PausePlayer", PausePlayer);
cmdList.InsertItem("RemoveFile", RemoveFile);
cmdList.InsertItem("ResumePlayer", ResumePlayer);
cmdList.InsertItem("SaveSettings", SaveSettings);
cmdList.InsertItem("SetMixerSettings", SetMixerSettings);
cmdList.InsertItem("SetOutputAgent", SetOutputAgent);
cmdList.InsertItem("SetPosition", SetPosition);
cmdList.InsertItem("SetVolume", SetVolume);
cmdList.InsertItem("StartedNormally", StartedNormally);
cmdList.InsertItem("StartPlayer", StartPlayer);
cmdList.InsertItem("StopPlayer", StopPlayer);
cmdList.InsertItem("UnloadFile", UnloadFile);
}
/******************************************************************************/
/* Destructor */
/******************************************************************************/
APClientCommunication::~APClientCommunication(void)
{
}
/******************************************************************************/
/* Start() will start the communications. */
/******************************************************************************/
void APClientCommunication::Start(void)
{
// Tell the global data object about this looper
globalData->communication->SetServerLooper(this);
// Start the BLooper
Run();
}
/******************************************************************************/
/* Stop() will stop all communications and delete itself. */
/******************************************************************************/
void APClientCommunication::Stop(void)
{
BMessenger messenger(NULL, this);
BMessage message(B_QUIT_REQUESTED);
// Tell the BLooper to quit and delete itself
// This call is synchronous, so we are sure the
// object has been deleted when the function
// call returns
messenger.SendMessage(&message, &message);
}
/******************************************************************************/
/* SendCommand() will send the command given to a specific client. */
/* */
/* Input: "player" is a pointer to the player that want to send a command. */
/* "command" is the command to send. */
/******************************************************************************/
void APClientCommunication::SendCommand(APPlayer *player, PString command)
{
BMessage message(APSERVER_MSG_DATA);
APFileHandle handle;
int32 i, count;
char *commandStr;
// Package the command into the message
message.AddString("Command", (commandStr = command.GetString()));
command.FreeBuffer(commandStr);
// Lock the file handle list
fileHandleList.LockList();
try
{
// Find the handle that have the player in it
count = fileHandleList.CountItems();
for (i = 0; i < count; i++)
{
// Get the handle
handle = fileHandleList.GetItem(i);
// Did we found the player?
if (handle.player == player)
{
// Yap, send the command to the client
handle.looper->PostMessage(&message);
break;
}
}
}
catch(...)
{
fileHandleList.UnlockList();
throw;
}
// Unlock the list again
fileHandleList.UnlockList();
}
/******************************************************************************/
/* SendCommandToAll() will send the command given to all clients. */
/* */
/* Input: "command" is the command to send. */
/******************************************************************************/
void APClientCommunication::SendCommandToAll(PString command)
{
BMessage message(APSERVER_MSG_DATA);
int32 i, count;
char *commandStr;
// Package the command into the message
message.AddString("Command", (commandStr = command.GetString()));
command.FreeBuffer(commandStr);
// Lock the client list
clientLoopers.LockList();
// Send to all the clients
count = clientLoopers.CountItems();
for (i = 0; i < count; i++)
{
// Send the message
clientLoopers.GetItem(i)->PostMessage(&message);
}
// Unlock the list again
clientLoopers.UnlockList();
}
/******************************************************************************/
/* GetInstrumentList() will lock the list with the instruments and return a */
/* pointer to it. */
/* */
/* Input: "fileHandle" is the file handle to the module. */
/* */
/* Output: A pointer to the list or NULL. */
/******************************************************************************/
const PList<APInstInfo *> *APClientCommunication::GetInstrumentList(uint32 fileHandle)
{
APFileHandle handle;
// Get the file information
if (!FindFileHandle(fileHandle, handle))
return (NULL);
// Return the list
return (handle.player->GetInstrumentList());
}
/******************************************************************************/
/* UnlockInstrumentList() unlocks the instrument list. */
/* */
/* Input: "fileHandle" is the file handle to the module. */
/******************************************************************************/
void APClientCommunication::UnlockInstrumentList(uint32 fileHandle)
{
APFileHandle handle;
// Get the file information
if (FindFileHandle(fileHandle, handle))
{
// Unlock the list
handle.player->UnlockInstrumentList();
}
}
/******************************************************************************/
/* GetSampleList() will lock the list with the samples and return a pointer */
/* to it. */
/* */
/* Input: "fileHandle" is the file handle to the module. */
/* */
/* Output: A pointer to the list or NULL. */
/******************************************************************************/
const PList<APSampleInfo *> *APClientCommunication::GetSampleList(uint32 fileHandle)
{
APFileHandle handle;
// Get the file information
if (!FindFileHandle(fileHandle, handle))
return (NULL);
// Return the list
return (handle.player->GetSampleList());
}
/******************************************************************************/
/* UnlockSampleList() unlocks the sample list. */
/* */
/* Input: "fileHandle" is the file handle to the module. */
/******************************************************************************/
void APClientCommunication::UnlockSampleList(uint32 fileHandle)
{
APFileHandle handle;
// Get the file information
if (FindFileHandle(fileHandle, handle))
{
// Unlock the list
handle.player->UnlockSampleList();
}
}
/******************************************************************************/
/* MessageReceived() is called for each message sent to the looper. */
/* */
/* Input: "message" is a pointer to the message that has been sent. */
/******************************************************************************/
void APClientCommunication::MessageReceived(BMessage *message)
{
switch (message->what)
{
//
// Connect
//
case APSERVER_MSG_CONNECT:
{
void *looper;
// Get looper from the message
if (message->FindPointer("ClientLooper", &looper) != B_OK)
{
// Could not find the pointer, send an error back
message->SendReply(APSERVER_MSG_ERROR);
}
else
{
// Got the looper, now remember it
clientLoopers.LockList();
clientLoopers.AddTail((BLooper *)looper);
clientLoopers.UnlockList();
// Send an ok back
message->SendReply(APSERVER_MSG_OK);
}
break;
}
//
// Disconnect
//
case APSERVER_MSG_DISCONNECT:
{
int32 i, count;
void *looper;
// Get looper from the message
if (message->FindPointer("ClientLooper", &looper) != B_OK)
{
// Could not find the pointer, send an error back
message->SendReply(APSERVER_MSG_ERROR);
}
else
{
// Got the looper, now remove it from the list
clientLoopers.LockList();
count = clientLoopers.CountItems();
for (i = 0; i < count; i++)
{
// Did we found the looper
if (clientLoopers.GetItem(i) == looper)
{
// Yup, remove it
clientLoopers.RemoveItem(i);
break;
}
}
// Unlock list
clientLoopers.UnlockList();
// Send an ok back
message->SendReply(APSERVER_MSG_OK);
// If this was the last client that has disconnected,
// close the server
if (count <= 1)
be_app->PostMessage(B_QUIT_REQUESTED);
}
break;
}
//
// Data
//
case APSERVER_MSG_DATA:
{
void *looper;
const char *cmd;
PString result;
if (message->FindPointer("ClientLooper", &looper) != B_OK)
{
// Could not find the pointer, send an error back
message->SendReply(APSERVER_MSG_ERROR);
}
else
{
// Get the command from the message
if (message->FindString("Command", &cmd) != B_OK)
{
// Could not find the command, send an error back
message->SendReply(APSERVER_MSG_ERROR);
}
else
{
BMessage reply;
char *resultStr;
//
// FUTURE: Make each command to run in its own thread if possible
//
;
// Parse the command
reply.what = ParseCommand((BLooper *)looper, cmd, result) ? APSERVER_MSG_OK : APSERVER_MSG_ERROR;
// Build reply message
if (!result.IsEmpty())
{
// Add the result
reply.AddString("Result", (resultStr = result.GetString()));
result.FreeBuffer(resultStr);
}
// Send the reply
message->SendReply(&reply);
}
}
break;
}
//
// Unknown message. Call the base class
//
default:
{
BLooper::MessageReceived(message);
break;
}
}
}
/******************************************************************************/
/* ParseCommand() will find out which command to run and split all the */
/* arguments. */
/* */
/* Input: "looper" is the looper where the command came from. */
/* "command" is the commmand with arguments. */
/* "result" is where the result should be stored. */
/* */
/* Output: True for success, false for failure. */
/******************************************************************************/
bool APClientCommunication::ParseCommand(BLooper *looper, PString command, PString &result)
{
PString cmd, temp;
PList<PString> args;
CommandFunc func;
int index;
// Start to extract the command
index = command.Find('=');
if (index == -1)
return (false);
cmd = command.Left(index);
command.Delete(0, index + 1);
// Now take all the arguments
while ((index = command.Find("\",")) != -1)
{
// Extract a single argument
temp = command.Mid(1, index - 1);
command.Delete(0, index + 2);
// Fix it
temp.Replace("/\"", "\"");
temp.Replace("//", "/");
// Add the argument to the list
args.AddTail(temp);
}
// Did we have any arguments left?
if (!command.IsEmpty())
{
// Yup, fix it
temp = command.Mid(1, command.GetLength() - 2);
temp.Replace("/\"", "\"");
temp.Replace("//", "/");
// And add it to the list
args.AddTail(temp);
}
// Find the command
if (!cmdList.GetItem(cmd, func))
{
// Unknown command
result.Format_S1(GetApp()->resource, IDS_CMDERR_UNKNOWN_COMMAND, cmd);
return (false);
}
// Found the command, now call it
return (func(this, looper, args, result));
}
/******************************************************************************/
/* FindFileHandle() will search the intern file handle list to see if it can */
/* find a handle with the unique ID given as the argument. */
/* */
/* Input: "uniqueID" is the file handle ID you want to find. */
/* "handle" is a reference where the handle will be stored. */
/* */
/* Output: True if the handle could be found, false if not. */
/******************************************************************************/
bool APClientCommunication::FindFileHandle(uint32 uniqueID, APFileHandle &handle)
{
int32 i, count;
// Lock the file handle list
fileHandleList.LockList();
try
{
// Find the file
count = fileHandleList.CountItems();
for (i = 0; i < count; i++)
{
// Get the handle
handle = fileHandleList.GetItem(i);
// Did we found the file?
if (handle.uniqueID == uniqueID)
{
// Yip, unlock the list
fileHandleList.UnlockList();
return (true);
}
}
}
catch(...)
{
fileHandleList.UnlockList();
throw;
}
// Unlock the list again
fileHandleList.UnlockList();
return (false);
}
/******************************************************************************/
/* SetFileHandle() will search the intern file handle list to see if it can */
/* find a handle with the unique ID given as the argument. If found, it */
/* will then overwrite it with the new handle given. */
/* */
/* Input: "uniqueID" is the file handle ID you want to find. */
/* "handle" is a reference to the new handle. */
/******************************************************************************/
void APClientCommunication::SetFileHandle(uint32 uniqueID, APFileHandle &handle)
{
APFileHandle searchHandle;
int32 i, count;
// Lock the file handle list
fileHandleList.LockList();
try
{
// Find the file
count = fileHandleList.CountItems();
for (i = 0; i < count; i++)
{
// Get the handle
searchHandle = fileHandleList.GetItem(i);
// Did we found the file?
if (searchHandle.uniqueID == uniqueID)
{
// Yip, overwrite it
fileHandleList.SetItem(handle, i);
break;
}
}
}
catch(...)
{
fileHandleList.UnlockList();
throw;
}
// Unlock the list again
fileHandleList.UnlockList();
}
/******************************************************************************/
/* FindAddOn() will search the list given after the specified add-on. */
/* */
/* Input: "addOnName" is the name of the add-on to search for. */
/* "infoList" is a pointer to the list to search in. */
/* "info" is a reference to where to store the information pointer. */
/* */
/* Output: True if the add-on was found, false if not. */
/******************************************************************************/
bool APClientCommunication::FindAddOn(PString addOnName, APMRSWList<AddOnInfo *> *infoList, AddOnInfo *&info)
{
int32 i, count;
bool found = false;
// Lock the list
infoList->WaitToRead();
count = infoList->CountItems();
for (i = 0; i < count; i++)
{
info = infoList->GetItem(i);
if (info->addOnName == addOnName)
{
// Found the add-on
found = true;
break;
}
}
// Unlock the list
infoList->DoneReading();
return (found);
}
/******************************************************************************/
/* DisableVirtualMixer() will search the file handler list and disable all */
/* relevant virtual mixers in the list. */
/* */
/* Input: "agent" is the agent to search for. */
/******************************************************************************/
void APClientCommunication::DisableVirtualMixer(AddOnInfo *agent)
{
int32 count, i;
// Lock the file handler list
fileHandleList.LockList();
// Traverse all the file handlers
count = fileHandleList.CountItems();
for (i = 0; i < count; i++)
{
// Disable the virtual mixer
fileHandleList.GetItem(i).player->DisableVirtualMixer(agent);
}
// Unlock the list again
fileHandleList.UnlockList();
}
/******************************************************************************/
/* */
/* Server commands */
/* */
/******************************************************************************/
/******************************************************************************/
/* AddFile() will add the file to an intern list. The file can then be used */
/* in other commands. */
/* */
/* Syntax: <handle> = AddFile=<file name> */
/* */
/* Input: "comm" is a pointer to the communication object. */
/* "looper" is a pointer to the client looper that sent this command. */
/* "args" is a list with all the arguments */
/* "result" is where the result should be stored. */
/* */
/* Output: True for success, false for failure. */
/******************************************************************************/
bool APClientCommunication::AddFile(APClientCommunication *comm, BLooper *looper, const PList<PString> &args, PString &result)
{
APFileHandle handle;
// Check the arguments
if (args.CountItems() != 1)
{
result.LoadString(GetApp()->resource, IDS_CMDERR_ARGLIST);
return (false);
}
// Create the file handle structure
handle.fileName = args.GetItem(0);
handle.player = NULL;
handle.looper = looper;
handle.mixerFrequency = 44100;
handle.interpolation = false;
handle.dolbyPrologic = false;
handle.amigaFilter = false;
// Create loader object
handle.loader = new APModuleLoader();
if (handle.loader == NULL)
throw PMemoryException();
// Lock the file handle list
comm->fileHandleList.LockList();
try
{
// Set the unique ID
if (comm->fileHandleList.CountItems() > 0)
handle.uniqueID = comm->fileHandleList.GetItem(comm->fileHandleList.CountItems() - 1).uniqueID + 1;
else
handle.uniqueID = 1;
// Add the handle to the list
comm->fileHandleList.AddTail(handle);
}
catch(...)
{
comm->fileHandleList.UnlockList();
throw;
}
// Unlock the list again
comm->fileHandleList.UnlockList();
// Return the handle
result.Format("%d", handle.uniqueID);
return (true);
}
/******************************************************************************/
/* CanChangePosition() will return if the player support position change. */
/* */
/* Syntax: <posChange> = CanChangePosition=<handle> */
/* */
/* Input: "comm" is a pointer to the communication object. */
/* "looper" is a pointer to the client looper that sent this command. */
/* "args" is a list with all the arguments */
/* "result" is where the result should be stored. */
/* */
/* Output: True for success, false for failure. */
/******************************************************************************/
bool APClientCommunication::CanChangePosition(APClientCommunication *comm, BLooper *looper, const PList<PString> &args, PString &result)
{
APFileHandle handle;
uint32 uniqueID;
bool posChange;
// Check the arguments
if (args.CountItems() != 1)
{
result.LoadString(GetApp()->resource, IDS_CMDERR_ARGLIST);
return (false);
}
// Convert the unique ID
uniqueID = args.GetItem(0).GetUNumber();
// Find the handle structure
if (!comm->FindFileHandle(uniqueID, handle))
{
result.LoadString(GetApp()->resource, IDS_CMDERR_INVALID_HANDLE);
return (false);
}
// Get the position change bool
posChange = handle.player->CanChangePosition();
// Store the result
result.SetUNumber(posChange);
return (true);
}
/******************************************************************************/
/* ChangeChannels() will change the channels in the mixer. */
/* */
/* Syntax: ChangeChannels=<handle>,<enable>,<startChan>,<stopChan> */
/* */
/* Input: "comm" is a pointer to the communication object. */
/* "looper" is a pointer to the client looper that sent this command. */
/* "args" is a list with all the arguments */
/* "result" is where the result should be stored. */
/* */
/* Output: True for success, false for failure. */
/******************************************************************************/
bool APClientCommunication::ChangeChannels(APClientCommunication *comm, BLooper * /*looper*/, const PList<PString> &args, PString &result)
{
APFileHandle handle;
uint32 uniqueID;
bool enable;
int32 startChan, stopChan;
// Check the arguments
if (args.CountItems() != 4)
{
result.LoadString(GetApp()->resource, IDS_CMDERR_ARGLIST);
return (false);
}
// Convert the unique ID
uniqueID = args.GetItem(0).GetUNumber();
// Get the other arguments
enable = args.GetItem(1).GetNumber();
startChan = args.GetItem(2).GetNumber();
stopChan = args.GetItem(3).GetNumber();
// Find the handle structure
if (!comm->FindFileHandle(uniqueID, handle))
{
result.LoadString(GetApp()->resource, IDS_CMDERR_INVALID_HANDLE);
return (false);
}
// Change the channels
if (handle.player != NULL)
handle.player->ChangeChannels(enable, startChan, stopChan);
return (true);
}
/******************************************************************************/
/* DisableAddOn() will disable the add-on. */
/* */
/* Syntax: DisableAddOn=<add-on name> */
/* */
/* Input: "comm" is a pointer to the communication object. */
/* "looper" is a pointer to the client looper that sent this command. */
/* "args" is a list with all the arguments */
/* "result" is where the result should be stored. */
/* */
/* Output: True for success, false for failure. */
/******************************************************************************/
bool APClientCommunication::DisableAddOn(APClientCommunication *comm, BLooper * /*looper*/, const PList<PString> &args, PString &result)
{
PString addOnName, sectionName;
AddOnInfo *addOn;
APMRSWList<AddOnInfo *> *addOnList;
// Check the arguments
if (args.CountItems() != 1)
{
result.LoadString(GetApp()->resource, IDS_CMDERR_ARGLIST);
return (false);
}
// Get the name of the add-on
addOnName = args.GetItem(0);
// Look for the add-on
addOnList = &GetApp()->playerInfo;
sectionName = "Player Add-Ons";
if (!comm->FindAddOn(addOnName, addOnList, addOn))
{
addOnList = &GetApp()->agentInfo;
sectionName = "Agent Add-Ons";
if (!comm->FindAddOn(addOnName, addOnList, addOn))
{
addOnList = &GetApp()->clientInfo;
sectionName = "Client Add-Ons";
if (!comm->FindAddOn(addOnName, addOnList, addOn))
{
result.Format_S1(GetApp()->resource, IDS_CMDERR_ADDON_NOT_FOUND, addOnName);
return (false);
}
}
}
// Lock the list
addOnList->WaitToWrite();
// Close any windows the add-on have open
GetApp()->addOnWindows->CloseAddOnWindows(addOn);
// Update the information list
addOn->enabled = false;
if (!addOn->allocated)
addOn->loader = NULL;
else
{
// Begin to unload the add-on.
// First see if the same player is elsewhere in the list
int32 i, count;
AddOnInfo *testItem;
bool found = false;
count = addOnList->CountItems();
for (i = 0; i < count; i++)
{
testItem = addOnList->GetItem(i);
if ((testItem != addOn) && (testItem->loader != NULL) && (testItem->fileName == addOn->fileName))
{
// Yeah we found one, set this add-on to the allocated one
testItem->allocated = true;
found = true;
break;
}
}
if (addOn->pluginFlags & apaVirtualMixer)
{
// Disable the mixer, so the main mixer won't call it anymore
comm->DisableVirtualMixer(addOn);
}
if (!found)
{
// Okay, this is the only instance of the add-on, so unload it
if (addOn->isAgent)
{
if (addOn->isClient)
{
// Plug-out the agent part
GetApp()->PlugAgentOut(addOn, false);
// Stop the client
((APAddOnClient *)addOn->agent)->EndClient(addOn->index);
// Delete the instance
addOn->loader->DeleteInstance(addOn->agent);
// Clear pointers
addOn->agent = NULL;
}
else
GetApp()->PlugAgentOut(addOn, true);
}
addOn->loader->Unload();
delete addOn->loader;
}
// Clear the rest of the info list
addOn->loader = NULL;
addOn->allocated = false;
}
// Write the new settings
GetApp()->useSettings->WriteStringEntryValue(sectionName, addOn->addOnName, "0," + addOn->fileName);
// Done with the list
addOnList->DoneWriting();
return (true);
}
/******************************************************************************/
/* EnableAddOn() will enable the add-on. */
/* */
/* Syntax: EnableAddOn=<add-on name> */
/* */
/* Input: "comm" is a pointer to the communication object. */
/* "looper" is a pointer to the client looper that sent this command. */
/* "args" is a list with all the arguments */
/* "result" is where the result should be stored. */
/* */
/* Output: True for success, false for failure. */
/******************************************************************************/
bool APClientCommunication::EnableAddOn(APClientCommunication *comm, BLooper * /*looper*/, const PList<PString> &args, PString &result)
{
PString addOnName, sectionName, dirName;
AddOnInfo *addOn;
APMRSWList<AddOnInfo *> *addOnList;
int32 i, count;
AddOnInfo *testItem;
APAddOnLoader *loader;
bool found;
// Check the arguments
if (args.CountItems() != 1)
{
result.LoadString(GetApp()->resource, IDS_CMDERR_ARGLIST);
return (false);
}
// Get the name of the add-on
addOnName = args.GetItem(0);
// Look for the add-on
addOnList = &GetApp()->playerInfo;
sectionName = "Player Add-Ons";
dirName = "Players";
if (!comm->FindAddOn(addOnName, addOnList, addOn))
{
addOnList = &GetApp()->agentInfo;
sectionName = "Agent Add-Ons";
dirName = "Agents";
if (!comm->FindAddOn(addOnName, addOnList, addOn))
{
addOnList = &GetApp()->clientInfo;
sectionName = "Client Add-Ons";
dirName = "Clients";
if (!comm->FindAddOn(addOnName, addOnList, addOn))
{