GPI Threading

A GPI runs in the ShapeUp main thread, but there is support for having 'collector threads' which asks for a synchronised call from ShapeUp when actions need to be taken. E.g. a collector thread could run and query an external data source, like GPS equipment, for updates. When an update occurrs, the GPI asks ShapeUp to get a synchronised call where it will take action on the event.

A sample thread function:

#define DATAUPDATE1 0
#define DATAUPDATE2 1
void MyThreadFunc()
{
    while (continueToRun)
    {
        if (DataAvailable())
            ShapeUp_WantUpdate(DATAUPDATE1);
        ...
    }
}

You can use different values as user data for the call to ShapeUp_WantUpdate() to distinguish different tasks.

A sample of the hook function might look like:

SURESULT __cdecl MyHookFunc(SUHANDLE hWorkspace, int hookType, SUHookData *args)
{
    // Here we are synchronized with the ShapeUp main thread, and we can call
    // any ShapeUp function.
    switch (hookType)
    {
    case HOOKTYPE_WANTUPDATE:
        switch (args->userData)
        {
        case DATAUPDATE1:
            ReadData1AndDoSomething();
            break;
        case DATAUPDATE2:
            ReadData2AndDoSomething();
            break;
        default:
            break;
        }
        break;
    default:
        break;
    }
    return SURESULT_OK;
}
See also:
ShapeUp_WantUpdate(), FNTYPE_SHAPEUP_WANTUPDATE, HOOKTYPE_WANTUPDATE
Make sure you have first read the introduction.
Generated on Thu Apr 15 10:55:34 2010 for ShapeUp API by  doxygen 1.5.2