thursday, 8 february 2007

posted at 22:22
tags:

packet.handler is coming along, but of course I hit yet another obstacle today. The loading mechanism I described previously is fine, except for a fatal flaw: OpenLibrary() loads shared libraries, meaning that I'll only get one instance of the packet handler ever. That would be fine, except that FATFileSystem (and probably every other) assumes it one unique instance per mount - it has global variables.

There are three ways around this that I can think of:

  • Implement my own loader that is basically a copypasta of the existing OpenLibrary() implementation. Duplicating that much code is an awful idea.
  • Hack up OpenLibrary() (or more specifically the LDDemon) to know about packet handlers and treat them specially. I'd feel really nervous about that - packet handlers are hardly "first class" objects like libraries and devices are.
  • Turn the packet handlers back into real processes, rather than libraries. That is, give them a main(), and call them from RunCommand().

I'm taking the latter option. Its sucks a little more for porters, as they have to add more code, though at least its minimal (and again, easily described). Its also a little weird in that it will make the handlers runnable from Workbench/CLI, though they won't do much. However, I'm going to recommend that the handler main() do a little bit of detection, and if thinks its being run by a user, to bail out. I believe a main() like the following should suffice:

void main(void) {
    if (((struct Process *) FindTask(NULL))->pr_TaskNum != 0) {
        printf("this is a filesystem handler, and can't be run directly\n");
        return;
    }

    startup();
}

I've run out of things to write, I suppose because I really haven't made much progress since this morning. Its getting late too, so I'm going to go to bed.