[solved] Using IDOS->NotifyVar() in library?
Posted: Fri Aug 09, 2013 9:37 pm
I'm trying to use IDOS->NotifyVar inside a library but the hookfunction gets never called.
Solution: I'm now creating my own "notify process" which installes the hook and stays alive as long as the library is not expunged.
I set up the hook in libInit():
In libOpen() when the opencounter is one I setup the NotifyVar():
success is != FALSE (it's DOSTRUE)
The prefsUpdateHook() function is:
But this doesn't work, why?
If I do the same in an stand alone program it works:
Solution: I'm now creating my own "notify process" which installes the hook and stays alive as long as the library is not expunged.
I set up the hook in libInit():
Code: Select all
libBase->prefsHook = IExec->AllocSysObjectTags(ASOT_HOOK,
ASOHOOK_Entry, prefsUpdateHook,
ASOHOOK_Subentry, NULL,
TAG_DONE);
Code: Select all
success = libBase->IDOS->NotifyVar("TestVar", libBase->prefsHook, NV_GLOBAL_NOTIFY, libBase);
The prefsUpdateHook() function is:
Code: Select all
void prefsUpdateHook(struct Hook *hook, CONST_APTR userdata, CONST_STRPTR name)
{
struct LibraryBase *libBase = (struct LibraryBase *)userdata;
#ifdef DEBUG
libBase->IExec->DebugPrintF("Function prefsUpdateHook called\n");
libBase->IExec->DebugPrintF("Function prefsUpdateHook userdata=%x\n", userdata);
libBase->IExec->DebugPrintF("Function prefsUpdateHook name=%s\n", name);
#endif
libBase->IExec->MutexObtain(libBase->lockMutex);
readPrefs(libBase);
libBase->IExec->MutexRelease(libBase->lockMutex);
}
If I do the same in an stand alone program it works:
Code: Select all
#include <proto/exec.h>
#include <proto/dos.h>
void prefsUpdateHook(struct Hook *hook, CONST_APTR userdata, CONST_STRPTR name)
{
IExec->DebugPrintF("Function prefsUpdateHook called\n");
IExec->DebugPrintF("Function prefsUpdateHook userdata=%x\n", userdata);
IExec->DebugPrintF("Function prefsUpdateHook name=%s\n", name);
}
int main(void)
{
struct Hook *hook;
int32 success;
hook = IExec->AllocSysObjectTags(ASOT_HOOK,
ASOHOOK_Entry, prefsUpdateHook,
ASOHOOK_Subentry, NULL,
TAG_DONE);
success = IDOS->NotifyVar("TestVar", hook, NV_GLOBAL_NOTIFY, (APTR)0xBAAAAAAD);
if (success)
{
IExec->Wait(SIGBREAKF_CTRL_C);
}
IDOS->NotifyVar(NULL, hook, NV_REMOVE_NOTIFY, NULL);
IExec->FreeSysObject(ASOT_HOOK, hook);
return 0;
}