Docky init.c openlib() problems

11 posts / 0 new
Last post
jabirulo
jabirulo's picture
Offline
Last seen: 6 days 2 hours ago
Joined: 2013-05-30 00:53
Docky init.c openlib() problems
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:
  1. ..
  2. struct MsgPort *AHImp = NULL, *TimerMP = NULL;
  3. struct Library *AHIBase = NULL, *TimerBase = NULL;
  4. struct AHIRequest *AHIio = NULL;
  5. struct TimeRequest *TimerIO = NULL;
  6. struct TimerIFace *ITimer = NULL;
  7. ..
  8. /* Expunge the library */
  9. APTR libExpunge(struct LibraryManagerInterface *Self)
  10. {// If your library cannot be expunged, return 0
  11. ..
  12. #ifdef IDEBUG
  13. IExec->DebugPrintF("[mixer.docky]libExpunge\n");
  14. #endif
  15. if(libBase->lib_OpenCnt == 0)
  16. {
  17. result = (APTR)DockyLibBase->SegList;
  18. // Undo what the init code did
  19. closeLibs();
  20.  
  21. IExec->Remove( (struct Node *)libBase );
  22. IExec->DeleteLibrary( (struct Library *)libBase );
  23. }
  24. ..
  25. }
  26.  
  27. /* The ROMTAG Init Function */
  28. struct Library *libInit(struct Library *libBase, APTR seglist, struct Interface *exec)
  29. {
  30. ..
  31. DockyLibBase->SegList = seglist;
  32. #ifdef IDEBUG
  33. IExec->DebugPrintF("[mixer.docky]libInit\n");
  34. #endif
  35. if( openLibs() ) return libBase;
  36.  
  37. closeLibs();
  38. return NULL;
  39. }
  40.  
  41. BOOL openLibs(void)
  42. {
  43. ..
  44. AHImp = (struct MsgPort *)IExec->AllocSysObject(ASOT_PORT, NULL);
  45. if(!AHImp) return FALSE;
  46. #ifdef IDEBUG
  47. IExec->DebugPrintF("[mixer.docky]openLibs(AHI_Port)\n");
  48. #endif
  49. AHIio = IExec->AllocSysObjectTags(ASOT_IOREQUEST, ASOIOR_Size,sizeof(*AHIio),
  50. ASOIOR_ReplyPort,AHImp, TAG_END);
  51. if(!AHIio) return FALSE;
  52. AHIio->ahir_Version = 5;
  53. if( IExec->OpenDevice(AHINAME, AHI_NO_UNIT, (struct IORequest *)AHIio, 0L) )
  54. return FALSE;
  55. AHIBase = (struct Library *)AHIio->ahir_Std.io_Device;
  56. if(!AHIBase) return FALSE;
  57.  
  58. TimerMP = (struct MsgPort *)IExec->AllocSysObject(ASOT_PORT, NULL);
  59. if(!TimerMP) return FALSE;
  60. #ifdef IDEBUG
  61. IExec->DebugPrintF("[mixer.docky]openLibs(TIMER_Port)\n");
  62. #endif
  63. TimerIO = IExec->AllocSysObjectTags(ASOT_IOREQUEST, ASOIOR_Size,sizeof(*TimerIO),
  64. ASOIOR_ReplyPort,TimerMP, TAG_END);
  65. if(!TimerIO) return FALSE;
  66. if( IExec->OpenDevice(TIMERNAME, UNIT_MICROHZ, (struct IORequest *)TimerIO, 0L) )
  67. return FALSE;
  68. TimerBase = (struct Library *)TimerIO->Request.io_Device;
  69. if(!TimerBase) return FALSE;
  70. ITimer = (struct TimerIFace *)IExec->GetInterface( (struct Library *)TimerBase, "main", 1, NULL );
  71. if(!ITimer) return FALSE;
  72. ..
  73. void closeLibs(void)
  74. {
  75. ..
  76.  
  77. IExec->DropInterface( (struct Interface *)ITimer );
  78. IExec->CloseDevice( (struct IORequest *)TimerIO );
  79. IExec->FreeSysObject(ASOT_IOREQUEST, TimerIO);
  80. TimerIO = NULL;
  81. IExec->FreeSysObject(ASOT_PORT, TimerMP);
  82. TimerMP = NULL;
  83. #ifdef IDEBUG
  84. IExec->DebugPrintF("[mixer.docky]closeLibs(TIMER)\n");
  85. #endif
  86.  
  87. IExec->CloseDevice( (struct IORequest *)AHIio );
  88. IExec->FreeSysObject(ASOT_IOREQUEST, AHIio);
  89. AHIio = NULL;
  90. IExec->FreeSysObject(ASOT_PORT, AHImp);
  91. AHImp = NULL;
  92. #ifdef IDEBUG
  93. IExec->DebugPrintF("[mixer.docky]closeLibs(AHI)\n");
  94. #endif
hypex
hypex's picture
Offline
Last seen: 1 day 6 hours ago
Joined: 2011-09-09 16:20
Won't your sizeof ( * AHIio )
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. :-)
jabirulo
jabirulo's picture
Offline
Last seen: 6 days 2 hours ago
Joined: 2013-05-30 00:53
Ok, THX will try with those
Ok, THX will try with those change and post here results. THX mate
AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P
jabirulo
jabirulo's picture
Offline
Last seen: 6 days 2 hours ago
Joined: 2013-05-30 00:53
Tried with those changes
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
salass00
salass00's picture
Offline
Last seen: 2 months 3 days ago
Joined: 2011-02-03 11:27
Won't your sizeof ( * AHIio )
Won't your sizeof ( * AHIio ) and sizeof ( * TimerIO ) return "4" as you are asking for the size of a pointer?
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.
salass00
salass00's picture
Offline
Last seen: 2 months 3 days ago
Joined: 2011-02-03 11:27
@jabirulo The reason your
@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:
  1. mp = AllocSysObjectTags(ASOT_PORT,
  2. ASOPORT_AllocSig, FALSE,
  3. TAG_END);
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.
  1. mp->mp_SigBit = IExec->AllocSignal(-1);
  2. mp->mp_SigTask = IExec->FindTask(NULL);
  3. mp->mp_Flags = PA_SIGNAL;
  4.  
  5. /* do your io stuff here */
  6.  
  7. mp->mp_Flags = PA_IGNORE;
  8. IExec->FreeSignal((int8)mp->mp_SigBit);
  9. mp->mp_SigBit = -1;
  10. mp->mp_SigTask = NULL;
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.
hypex
hypex's picture
Offline
Last seen: 1 day 6 hours ago
Joined: 2011-09-09 16:20
No, it won't because he isn't
No, it won't because he isn't doing that (asking for the size of a pointer).
Sorry guys, thought I had read something about that before. Just a rushed late night post. :-)
jabirulo
jabirulo's picture
Offline
Last seen: 6 days 2 hours ago
Joined: 2013-05-30 00:53
Sorry for delay (again) I
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
salass00
salass00's picture
Offline
Last seen: 2 months 3 days ago
Joined: 2011-02-03 11:27
@jabirulo Read the autodoc
@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.
jabirulo
jabirulo's picture
Offline
Last seen: 6 days 2 hours ago
Joined: 2013-05-30 00:53
Yes, already read that
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
jabirulo
jabirulo's picture
Offline
Last seen: 6 days 2 hours ago
Joined: 2013-05-30 00:53
@salass00 Replaced
@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
Log in or register to post comments