Hi using AmiDock/applib skeletondocky init.c to create a Mixer.docky (almost done, only shows master volume) and sometimes it doesn't open AHI/Timer MsgPort.
It always fails when trying to open the 2nd MsgPort, no matter if its AHI or Timer.
Any ideas what is going on? Am I doing something theWrongwayTM?
TIA
Parts of the code I use in init.c:
.. struct MsgPort *AHImp = NULL, *TimerMP = NULL; struct Library *AHIBase = NULL, *TimerBase = NULL; struct AHIRequest *AHIio = NULL; struct TimeRequest *TimerIO = NULL; struct TimerIFace *ITimer = NULL; .. /* Expunge the library */ APTR libExpunge(struct LibraryManagerInterface *Self) {// If your library cannot be expunged, return 0 .. #ifdef IDEBUG IExec->DebugPrintF("[mixer.docky]libExpunge\n"); #endif if(libBase->lib_OpenCnt == 0) { result = (APTR)DockyLibBase->SegList; // Undo what the init code did closeLibs(); IExec->Remove( (struct Node *)libBase ); IExec->DeleteLibrary( (struct Library *)libBase ); } .. } /* The ROMTAG Init Function */ struct Library *libInit(struct Library *libBase, APTR seglist, struct Interface *exec) { .. DockyLibBase->SegList = seglist; #ifdef IDEBUG IExec->DebugPrintF("[mixer.docky]libInit\n"); #endif if( openLibs() ) return libBase; closeLibs(); return NULL; } BOOL openLibs(void) { .. AHImp = (struct MsgPort *)IExec->AllocSysObject(ASOT_PORT, NULL); if(!AHImp) return FALSE; #ifdef IDEBUG IExec->DebugPrintF("[mixer.docky]openLibs(AHI_Port)\n"); #endif AHIio = IExec->AllocSysObjectTags(ASOT_IOREQUEST, ASOIOR_Size,sizeof(*AHIio), ASOIOR_ReplyPort,AHImp, TAG_END); if(!AHIio) return FALSE; AHIio->ahir_Version = 5; if( IExec->OpenDevice(AHINAME, AHI_NO_UNIT, (struct IORequest *)AHIio, 0L) ) return FALSE; AHIBase = (struct Library *)AHIio->ahir_Std.io_Device; if(!AHIBase) return FALSE; TimerMP = (struct MsgPort *)IExec->AllocSysObject(ASOT_PORT, NULL); if(!TimerMP) return FALSE; #ifdef IDEBUG IExec->DebugPrintF("[mixer.docky]openLibs(TIMER_Port)\n"); #endif TimerIO = IExec->AllocSysObjectTags(ASOT_IOREQUEST, ASOIOR_Size,sizeof(*TimerIO), ASOIOR_ReplyPort,TimerMP, TAG_END); if(!TimerIO) return FALSE; if( IExec->OpenDevice(TIMERNAME, UNIT_MICROHZ, (struct IORequest *)TimerIO, 0L) ) return FALSE; TimerBase = (struct Library *)TimerIO->Request.io_Device; if(!TimerBase) return FALSE; ITimer = (struct TimerIFace *)IExec->GetInterface( (struct Library *)TimerBase, "main", 1, NULL ); if(!ITimer) return FALSE; .. void closeLibs(void) { .. IExec->DropInterface( (struct Interface *)ITimer ); IExec->CloseDevice( (struct IORequest *)TimerIO ); IExec->FreeSysObject(ASOT_IOREQUEST, TimerIO); TimerIO = NULL; IExec->FreeSysObject(ASOT_PORT, TimerMP); TimerMP = NULL; #ifdef IDEBUG IExec->DebugPrintF("[mixer.docky]closeLibs(TIMER)\n"); #endif IExec->CloseDevice( (struct IORequest *)AHIio ); IExec->FreeSysObject(ASOT_IOREQUEST, AHIio); AHIio = NULL; IExec->FreeSysObject(ASOT_PORT, AHImp); AHImp = NULL; #ifdef IDEBUG IExec->DebugPrintF("[mixer.docky]closeLibs(AHI)\n"); #endif
Won't your sizeof ( * AHIio ) and sizeof ( * TimerIO ) return "4" as you are asking for the size of a pointer?
I'd be implcit and use sizeof(struct AHIRequest) and size(struct TimeRequest) instead. See how that goes. :-)
Ok, THX will try with those change and post here results. THX mate
AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P
Tried with those changes 'struct AHIRequest' and 'struct TimeRequest' but happens teh same afater a few quit/load Mixer.docky the 2nd MsgPort (now TimerMP) doesn't open. :-/
Any other ideas/changes I can do to track/solve such problem? TIA
AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P
No, it won't because he isn't doing that (asking for the size of a pointer).
Because he is dereferencing the pointer (by using '*') sizeof() will return the size of the structure pointed to rather than the size of the pointer itself.
@jabirulo
The reason your code doesn't work is that each time you are creating a msgport in libInit() you are allocating a signal from the ramlib task (in AmigaOS each task has only 32 signals out of which only IIRC 16 are free to allocate with AllocSignal() so eventually they will run out).
If your not going to be doing anything with the iorequests you should be able to just change the code for creating the msgports to:
If you want to do operations using the iorequests you need to allocate and free a signal as needed and set the mp_SigBit, mp_SigTask and mp_Flags fields appropriately.
Also you don't need to allocate a separate msgport for each iorequest although it might be convenient to do that sometimes for the sake of code modularity.
Sorry guys, thought I had read something about that before. Just a rushed late night post. :-)
Sorry for delay (again) I only use Timer's MicroDelay() function (it is used in Mixer.docky by the soundcards initialization code), so it seems fine to 'ASOPORT_AllocSig, FALSE' (I don't need th 2nd part of code you posted or do I?). Will post here results. THX.
AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P
@jabirulo
Read the autodoc for MicroDelay(). It should only be used for used for very short delays and only when regular methods don't work like when multitasking is disabled or when running inside an interrupt. MicroDelay() busy waits which means that the time you spend in it is wasted and can't be used by other programs.
If you open newlib.library in your libInit function you have access to usleep() which is used in the same way as MicroDelay() only it is multitasking friendly unlike MicroDelay() and you don't have to bother with the timer.device opening and closing.
Yes, already read that MicroDelay() should be used for very short delays (IIRC something like that was posted here time ago).
Anyway, changed to use usleep() and removed Timer open/close.
Hope it works fine. THX again.
AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P
@salass00
Replaced timer.device with sleep()/usleep() and no problems/issues in Mixer.docky
Changed in original Mixer too and so far no problems/issues.
THX THX THX
AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P