posixc.library: convert path unix2amiga in rmdir before passing to stdcio remove
[AROS.git] / workbench / libs / camd / init.c
blobbf93df265445400b913a3cb6ffa013c51de4a2ed
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
9 #include <proto/dos.h>
10 #include <proto/exec.h>
11 #include <proto/camd.h>
12 #include <proto/utility.h>
14 #include "camd_intern.h"
17 #ifdef __amigaos4__
18 BOOL InitCamd(struct CamdIFace *ICamd){
19 CAMD_LIBBASE_DECL(struct CamdBase *,CamdBase)
20 #else
21 BOOL InitCamd(struct CamdBase *CamdBase){
22 #endif
23 struct FileInfoBlock fib;
24 BPTR lock;
25 char temp[256];
27 CB(CamdBase)->CLSemaphore=AllocMem(sizeof(struct SignalSemaphore),MEMF_ANY|MEMF_CLEAR|MEMF_PUBLIC);
28 if(CB(CamdBase)->CLSemaphore==NULL){
29 return FALSE;
31 InitSemaphore(CB(CamdBase)->CLSemaphore);
32 #ifndef __amigaos4__
33 NEWLIST(&CB(CamdBase)->mymidinodes);
34 NEWLIST(&CB(CamdBase)->midiclusters);
35 NEWLIST(&CB(CamdBase)->clusnotifynodes);
36 #else // ???
37 NEWLIST(CB(CamdBase)->mymidinodes);
38 NEWLIST(CB(CamdBase)->midiclusters);
39 NEWLIST(CB(CamdBase)->clusnotifynodes);
40 #endif
41 if(InitCamdTimer()==FALSE) return FALSE;
42 lock=Lock("devs:Midi",ACCESS_READ);
43 if(lock==0){
44 return TRUE;
46 if(Examine(lock,&fib)==FALSE){
47 UnLock(lock);
48 return TRUE;
50 while(ExNext(lock,&fib)!=FALSE){
51 mysprintf(CamdBase,temp,"devs:Midi/%s",fib.fib_FileName);
52 #ifdef __amigaos4__
53 LoadDriver(temp,ICamd);
54 #else
55 LoadDriver(temp,CamdBase);
56 #endif
58 UnLock(lock);
59 return TRUE;
62 #ifdef __amigaos4__
63 void UninitCamd(struct CamdIFace *ICamd){
64 CAMD_LIBBASE_DECL(struct CamdBase *,CamdBase)
65 #else
66 void UninitCamd(struct CamdBase *CamdBase){
67 #endif
68 struct Drivers *driver=CB(CamdBase)->drivers,*temp2;
69 struct Node *node,*temp;
70 struct MidiCluster *midicluster;
71 struct DriverData *driverdata;
73 if( ! IsListEmpty(&CB(CamdBase)->midiclusters)){
74 node=CB(CamdBase)->midiclusters.lh_Head;
75 while(node->ln_Succ!=NULL){
76 temp=node->ln_Succ;
77 midicluster=(struct MidiCluster *)node;
78 driverdata=FindSenderDriverInCluster(midicluster);
79 if(driverdata==NULL){
80 driverdata=FindReceiverDriverInCluster(midicluster);
82 if(driverdata!=NULL){
83 if(driverdata->isInOpen==TRUE || driverdata->isOutOpen==TRUE){
84 driverdata->isInOpen=FALSE;
85 driverdata->isOutOpen=FALSE;
86 CloseDriver(driverdata,CamdBase);
88 }else{
89 RemoveCluster((struct MidiCluster *)node,CamdBase); //Clients should have do this, but..
91 node=temp;
95 while(driver!=NULL){
96 temp2=driver->next;
97 (*driver->mididevicedata->Expunge)();
98 FreeDriverData(driver,CamdBase);
99 CloseMidiDevice(driver->mididevicedata);
100 driver=temp2;
103 if(CB(CamdBase)->CLSemaphore!=NULL)
104 FreeMem(CB(CamdBase)->CLSemaphore,sizeof(struct SignalSemaphore));
106 UninitCamdTimer();