void FskGtkWindowSetMenuItemCallback(FskGtkWindow win, GtkWidget* menuItem, int id) { menuItems entry = NULL; if(kFskErrNone == FskMemPtrNewClear(sizeof(menuItemsRecord), (FskMemPtr*)&entry)) { menuBars entryBar = NULL; entry->win = win; entry->id = id; entry->item= menuItem; FskMutexAcquire(win->menuMutex); entryBar = win->menu; while(entryBar) { if(entryBar->id == (id & 0xFF00)) { break; } entryBar = entryBar->next; } if(entryBar) { FskListAppend(&entryBar->menulist, entry); g_signal_connect(menuItem, "activate", G_CALLBACK(on_menu_select_cb), (gpointer)entry); } FskMutexRelease(win->menuMutex); } }
FskErr FskFSVolumeNotifierNew(FskVolumeNotifierCallbackProc callback, void *refCon, FskFSVolumeNotifier *volNtfOut) { FskErr err; FskFSVolumeNotifier volNtf = NULL; FskAndroidFilesPrintfDebug("VolumeNotifierNew\n"); if (NULL == gVolNotifiers) { err = FskMutexNew(&gVolNotifiersMutex, "volume notifier"); BAIL_IF_ERR(err); } err = FskMemPtrNewClear(sizeof(FskFSVolumeNotifierRecord), (FskMemPtr*)(void*)&volNtf); BAIL_IF_ERR(err); FskMutexAcquire(gVolNotifiersMutex); volNtf->dispatch.dispatch = &gFSDispatch; volNtf->dispatch.refcon = NULL; volNtf->callback = callback; volNtf->refCon = refCon; volNtf->callbackThread = FskThreadGetCurrent(); FskListPrepend(&gVolNotifiers, &volNtf->next); FskMutexRelease(gVolNotifiersMutex); bail: *volNtfOut = volNtf; return err; }
int linuxAudioOutPCM(FskAudioOut audioOut, char *p, int size) { FskErr err = kFskErrNone; FskAudioOutBlock audioBlock; androidAudioExt *ext = (androidAudioExt*)audioOut->ext; int wrote = 0, remains = 0; int origSize = size; if (NULL == audioOut->blocks->list) goto bail; if (0 != FskMutexTrylock(audioOut->blocks->mutex)) { FskMutexAcquire(audioOut->blocks->mutex); } //FskAudioNativePrintfDebug("before FskListMutex - grabbed blocks %x (blocks)", audioOut->blocks); while (size) { char *pos; audioBlock = (FskAudioOutBlock)audioOut->blocks->list; while (audioBlock && audioBlock->done) { audioBlock = audioBlock->next; } if (!audioBlock) { if (0 == ext->bytesEnqueued) { FskAudioNativePrintfMinimal("no more free PCM blocks to play"); FskAudioNativePrintfMinimal(" - there are %u bytes enqueued - wanted %d (orig size %d)", (unsigned)ext->bytesEnqueued, size, origSize); } goto bail; } if (audioBlock->loc) // remainder pos = audioBlock->loc; else pos = (char*)audioBlock->data; if (audioBlock->dataSize <= (unsigned)size) { FskMemCopy(p, pos, audioBlock->dataSize); wrote += audioBlock->dataSize; p += audioBlock->dataSize; size -= audioBlock->dataSize; ext->bytesEnqueued -= audioBlock->dataSize; audioBlock->dataSize = 0; // only setting this for a debug message audioBlock->done = true; continue; } else { FskMemCopy(p, pos, size); wrote += size; audioBlock->loc = pos + size; audioBlock->dataSize -= size; FskAudioNativePrintfDebug("Consuming %d bytes (block left: %d) (total left %d)", size, audioBlock->dataSize, ext->bytesEnqueued - size); ext->bytesEnqueued -= size; size = 0; break; } } bail: FskMutexRelease(audioOut->blocks->mutex); return wrote; }
// --------------------------------------------------------------------- FskErr FskNetInterfaceDescribe(int idx, FskNetInterfaceRecord **iface) { int i = 0; FskErr ret = kFskErrNone; FskNetInterfaceRecord *nir; FskMutexAcquire(gNetworkInterfaceList->mutex); nir = (FskNetInterfaceRecord *)gNetworkInterfaceList->list; while (nir) { if (i == idx) break; nir = nir->next; i++; } if (nir) { FskNetInterfaceRecord *dup; if (kFskErrNone == FskMemPtrNewFromData(sizeof(FskNetInterfaceRecord), nir, &dup)) { dup->next = NULL; dup->name = FskStrDoCopy(nir->name); } *iface = dup; } else { *iface = NULL; ret = kFskErrNetworkInterfaceNotFound; } FskMutexRelease(gNetworkInterfaceList->mutex); return ret; }
void devFBFlip(KplScreen screen) { UInt32 dummy; struct fb_var_screeninfo *var = &screen->vinfo; Boolean skipCopy = (0 == screen->bitmapsReady); // Boolean skipCopy = 1; if (skipCopy) { ioctl(screen->fbfd, FBIO_WAITFORVSYNC, &dummy); return; } FskMutexAcquire(screen->withCare); // FskMemMove(screen->baseAddr[OFFSCREEN_PAGE(screen)], screen->bitmaps[1 & screen->bitmapsFlagRead]->bits, gScreenWidth * gScreenHeight * 2); FskMemMove(screen->baseAddr[OFFSCREEN_PAGE(screen)], screen->bitmaps[0]->bits, gScreenWidth * gScreenHeight * 2); screen->bitmapsFlagRead += 1; screen->bitmapsReady -= 1; FskMutexRelease(screen->withCare); if (ioctl(screen->fbfd, FBIO_WAITFORVSYNC, &dummy) < 0) { fprintf(stderr, " devFBFlip - problems with WAITFORVSYNC - %d\n", errno); } screen->displayPage = OFFSCREEN_PAGE(screen); #if 0 var->xoffset = 0; var->yoffset = DISPLAY_OFFSET(screen); var->activate = FB_ACTIVATE_VBL; if (ioctl(screen->fbfd, FBIOPAN_DISPLAY, var) < 0) { fprintf(stderr, " devFBFlip - problems with PAN - %d\n", errno); } #endif }
FskErr androidAudioOutGetSamplePosition(FskAudioOut audioOut, FskSampleTime *position) { androidAudioExt *ext = (androidAudioExt*)audioOut->ext; FskInt64 add; FskErr err = kFskErrNone; SLresult res; UInt32 pos; FskMutexAcquire(ext->getSamplePositionMutex); *position = audioOut->zeroTime; if (audioOut->playing) { SLmillisecond msec; res = (*ext->playItf)->GetPosition(ext->playItf, &msec); CheckErr(" audioOutGetSamplePosition", res); add = MSToSamples(audioOut, msec); pos = (UInt32)add; FskAudioNativePrintfVerbose("GetSamplePosition returns msec: %d, pos: %d", msec, pos); } else { add = ext->stoppedAtSamplePosition; } add -= ext->startedAtSamplePosition; *position += add; FskAudioNativePrintfVerbose("getSamplePosition %d - %d ms -- start@ %d, last stop@ %d, zero@ %lld", (UInt32)*position, (*position * 1000) / audioOut->sampleRate , (UInt32)ext->startedAtSamplePosition, (UInt32)ext->stoppedAtSamplePosition, audioOut->zeroTime); releaseAndBail: FskMutexRelease(ext->getSamplePositionMutex); return err; }
void BufferQueueCallback(SLAndroidSimpleBufferQueueItf queueItf, void *pContext) { SLresult res; androidAudioExt *ext = (androidAudioExt*)pContext; FskAudioOut aOut = (FskAudioOut)ext->parent; Boolean isValid = false; int amt, written = 0; FskMutexAcquire(gActiveAudioMutex); if (!aOut) { FskAudioNativePrintfMinimal("In BQ callback - audioOut is NULL - bail"); goto bail; } androidAudioOutIsValid(aOut, &isValid); if (!isValid || !aOut->playing) { FskAudioNativePrintfMinimal("In BQ callback - aOut is invalid %p || not playing", aOut); goto bail; } if (ext->audioFilled[ext->nextBuf]) { FskAudioNativePrintfDebug("BQCallback: buffer %d is filled and has %d bytes to enqueue.", ext->nextBuf, ext->audioFilled[ext->nextBuf]); res = (*queueItf)->Enqueue(queueItf, (void*)ext->audioBuf[ext->nextBuf], ext->audioFilled[ext->nextBuf]); CheckErr("BufferQueueCallback - Enqueue data", res); if (SL_RESULT_SUCCESS == res) { written += ext->audioFilled[ext->nextBuf]; ext->audioFilled[ext->nextBuf] = 0; ext->nextBuf = ext->nextBuf ? 0 : 1; } } else { FskAudioNativePrintfDebug("BQCallback: buffer wasn't filled - what to do? a: %d, b: %d", ext->audioFilled[0], ext->audioFilled[1]); } if (!ext->audioFilled[ext->nextBuf]) { FskAudioNativePrintfDebug("BQCallback: buffer %d is not filled - attempting to fill", ext->nextBuf); amt = linuxAudioOutPCM(aOut, ext->audioBuf[ext->nextBuf], AUDIO_DATA_BUFFER_SIZE); if (amt > 0) { FskAudioNativePrintfDebug(" buffer %d filled with %d bytes", ext->nextBuf, amt); ext->audioFilled[ext->nextBuf] = amt; } else { FskAudioNativePrintfMinimal(" buffer %d didn't fill", ext->nextBuf); ext->audioFilled[ext->nextBuf] = 0; } } bail: if (!written) { FskAudioNativePrintfMinimal("TRY - nothing written to output - stall?"); androidAudioOutGetSamplePosition(aOut, &ext->stoppedAtSamplePosition); res = (*ext->playItf)->SetPlayState(ext->playItf, SL_PLAYSTATE_STOPPED); aOut->playing = false; } else { // FskAudioNativePrintfDebug("wrote - written: %d", written); } FskMutexRelease(gActiveAudioMutex); return; }
void removeFromQueue(FskAudioOut audioOut, UInt32 what) { int freed = 0; androidAudioExt *ext; FskAudioNativePrintfVerbose("removeFromQueue %x", what); if (audioOut->blocks) { int err; err = FskMutexTrylock(audioOut->blocks->mutex); if (err != 0) { FskAudioNativePrintfMinimal("removeUnusedFrom Queue - trylock was busy"); return; } while (true) { FskAudioOutBlock block = (FskAudioOutBlock)audioOut->blocks->list; if ((NULL == block) || ((what == kUsed) & (false == block->done))) break; block = (FskAudioOutBlock)FskListRemoveFirst((FskList*)&audioOut->blocks->list); if (block->silence) FskMemPtrDispose(block->data); else if (audioOut->doneCB) { if (block->dataSize && (what != kAll)) { ext = (androidAudioExt*)audioOut->ext; FskAudioNativePrintfMinimal("TRASHING audioblock with some data left: %u bytes - (total left %u)", (unsigned)block->dataSize, (unsigned)(ext->bytesEnqueued - block->dataSize)); ext->bytesEnqueued -= block->dataSize; } (audioOut->doneCB)(audioOut, audioOut->doneRefCon, block->refCon, true); } FskMemPtrDispose(block->frameSizes); FskMemPtrDispose(block); freed++; } FskMutexRelease(audioOut->blocks->mutex); } }
FskErr FskNetInterfaceInitialize(void) { FskErr err; err = FskListMutexNew(&interfaceChangeCBList, "interfaceChangeCBLIst"); if (err) return err; #if TARGET_OS_WIN32 installWindowsNetworkInterfaceChangeTracker(); #elif TARGET_OS_IPHONE installIOSNetworkInterfaceChangeTracker(); #elif TARGET_OS_MAC installMacNetworkInterfaceChangeTracker(); #endif /* TARGET_OS */ #if TARGET_OS_KPL KplNetInterfaceInitialize(); KplNetInterfaceSetChangedCallback(KplNetInterfaceChanged, 0L); #endif /* TARGET_OS_KPL */ err = FskListMutexNew(&gNetworkInterfaceList, "gNetworkInterfaceList"); if (err) return err; FskMutexAcquire(gNetworkInterfaceList->mutex); sFskNetInterfaceEnumerate((FskNetInterfaceRecord**)(void*)&gNetworkInterfaceList->list); FskMutexRelease(gNetworkInterfaceList->mutex); return err; }
void Library_cacheQuery(xsMachine* the) { KprLibraryServer self = gLibraryServer; UInt32 index; KprLibraryQuery query; FskMutexAcquire(self->queryMutex); index = self->queryIndex % kQueryCount; query = self->queries[index]; if (query) { KprLibraryQueryDispose(query); self->queries[index] = NULL; } KprLibraryQueryNew(&query); FskInstrumentedItemSetOwner(query, self); xsEnterSandbox(); query->index = self->queryIndex; query->info = FskStrDoCopy(xsToString(xsGet(xsArg(0), xsID("info")))); query->kind = xsToInteger(xsGet(xsArg(0), xsID("kind"))); query->mime = FskStrDoCopy(xsToString(xsGet(xsArg(0), xsID("mime")))); query->url = FskStrDoCopy(xsToString(xsGet(xsArg(0), xsID("url")))); xsResult = xsGet(xsArg(0), xsID("authorization")); if (xsTest(xsResult)) query->authorization = FskStrDoCopy(xsToString(xsResult)); xsLeaveSandbox(); self->queries[index] = query; xsResult = xsInteger(self->queryIndex); self->queryIndex++; FskMutexRelease(self->queryMutex); }
void FskGtkWindowInvalidDaRect(FskGtkWindow win, FskRectangle area) { FskMutexAcquire(win->bufMutex); if(win->pixbufDraw) g_object_unref(win->pixbufDraw); win->pixbufDraw = gdk_pixbuf_copy(win->pixbuf); FskMutexRelease(win->bufMutex); g_async_queue_push(win->queue, win); }
// Event handler: da->draw static gboolean draw_callback(GtkWidget *widget, cairo_t *cr, gpointer data) { FskGtkWindow win = (FskGtkWindow)data; FskMutexAcquire(win->bufMutex); if(win->pixbufDraw) gdk_cairo_set_source_pixbuf(cr, win->pixbufDraw, 0, 0); cairo_paint(cr); FskMutexRelease(win->bufMutex); return TRUE; }
FskErr FskFSVolumeNotifierDispose(FskFSVolumeNotifier volNtf) { FskAndroidFilesPrintfDebug("VolumeNotifierDispose\n"); FskMutexAcquire(gVolNotifiersMutex); FskListRemove((FskList *)&gVolNotifiers, &volNtf->next); FskMemPtrDispose(volNtf); FskMutexRelease(gVolNotifiersMutex); return kFskErrNone; }
static void InitGLCallback(void *vAWin, void *vUnused1, void *vUnused2, void *vUnused3) { ANativeWindow *aWin = (ANativeWindow*)vAWin; FskErr err; FskMutexAcquire(jniRespMutex); FskConditionSignal(jniRespCond); FskInstrumentedTypePrintfMinimal(&gAndroidMainBlockTypeInstrumentation, "[%p] InitGLCallback: calling FskGLInit(%p)", pthread_self(), aWin); err = FskGLInit(aWin); FskInstrumentedTypePrintfMinimal(&gAndroidMainBlockTypeInstrumentation, "[%p] InitGLCallback: FskGLInit(%p) returns err=%d", pthread_self(), aWin, (int)err); FskMutexRelease(jniRespMutex); }
FskErr androidAudioOutStart(FskAudioOut audioOut, FskSampleTime atSample) { FskErr err = kFskErrNone; androidAudioExt *ext = (androidAudioExt*)audioOut->ext; SLresult res; FskAudioNativePrintfVerbose("audioOutStart %x - atSample %lld", audioOut, atSample); if (audioOut->playing) goto bail; if (!ext->playItf) { FskAudioNativePrintfMinimal("huh? No playItf"); err = kFskErrOperationFailed; goto bail; } audioOut->zeroTime = atSample; ext->stoppedAtSamplePosition = 0; FskTimeCallbackNew(&ext->flushTimer); FskTimeCallbackScheduleFuture(ext->flushTimer, 0, kFlushAndRefillTime, flushNowCallback, audioOut); FskAudioNativePrintfVerbose("androidAudioOutStart %x - zeroTime %d", audioOut, audioOut->zeroTime); // in case volume has changed when audio was off // androidAudioOutSetVolume(audioOut, audioOut->leftVolume, audioOut->rightVolume); refillQueue(audioOut); fillBuffers(audioOut); audioOut->playing = true; // refillQueue(audioOut); FskTimeGetNow(&ext->lastTime); FskMutexAcquire(gActiveAudioMutex); gActiveAudioOut = audioOut; FskMutexRelease(gActiveAudioMutex); res = (*ext->playItf)->SetPlayState(ext->playItf, SL_PLAYSTATE_PLAYING); CheckErr(" audioOutStart - set playstate playing", res); { SLmillisecond msec; res = (*ext->playItf)->GetPosition(ext->playItf, &msec); CheckErr(" androidAudioOutStart", res); ext->startedAtSamplePosition = MSToSamples(audioOut, msec); } bail: return err; }
void androidVolumeEvent(int what, char *path) { UInt32 vid; FskFSVolumeNotifier walker = NULL; char *tmp = NULL; FskAndroidFilesPrintfDebug("androidVolumeEvent - %d, %s\n", what, path); if (NULL == gVolNotifiersMutex) return; FskMutexAcquire(gVolNotifiersMutex); if (0 == FskStrCompareWithLength(path, "file://", 7)) path += 7; if (path[FskStrLen(path)-1] != '/') tmp = FskStrDoCat(path, "/"); else tmp = FskStrDoCopy(path); FskFSVolumeGetID(tmp, &vid); FskAndroidFilesPrintfDebug("androidVolumeEvent - getvolumeid returned %d\n", vid); if (vid == kFskUInt32Max) { FskAndroidFilesPrintfDebug("couldn't find a mount for %s - try to scan again###\n", tmp); scanProcMount(); FskFSVolumeGetID(tmp, &vid); if (vid == 0) { FskAndroidFilesPrintfDebug("#### still no volume id? %s\n", tmp); } } while (gVolNotifiers) { FskFSVolumeNotifier notifier; walker = (FskFSVolumeNotifier)FskListGetNext(gVolNotifiers, walker); if (NULL == walker) break; FskAndroidFilesPrintfDebug("androidVolumeEvent - notifying %x\n", walker); notifier = (FskFSVolumeNotifier)(((char *)walker) - offsetof(FskFSVolumeNotifierRecord, next)); FskThreadPostCallback(notifier->callbackThread, callVolumeNotifier, notifier, (void*)what, (void*)vid, NULL); } FskMutexRelease(gVolNotifiersMutex); FskMemPtrDispose(tmp); }
void Library_getURI(xsMachine* the) { KprLibraryServer self = gLibraryServer; UInt32 queryIndex; UInt32 index; KprLibraryQuery query; FskMutexAcquire(self->queryMutex); queryIndex = xsToInteger(xsArg(0)); index = queryIndex % kQueryCount; query = self->queries[index]; if (query && (query->index == queryIndex)) xsResult = xsString(query->url); else xsResult = xsNull; FskMutexRelease(self->queryMutex); }
FskErr androidAudioOutStop(FskAudioOut audioOut) { androidAudioExt *ext; FskSampleTime pos; SLresult res; FskErr err = kFskErrNone; FskAudioNativePrintfVerbose("audioOutStop %x", audioOut); BAIL_IF_NULL(audioOut, err, kFskErrNone); ext = (androidAudioExt*)audioOut->ext; BAIL_IF_NULL(ext, err, kFskErrNone); if (ext->flushTimer) { FskAudioNativePrintfVerbose("%x -- Disposing of flushTimer", audioOut); FskTimeCallbackDispose(ext->flushTimer); ext->flushTimer = NULL; } if (!audioOut->playing) { FskAudioNativePrintfDebug(" -- wuzn't playin"); BAIL(kFskErrNone); } androidAudioOutGetSamplePosition(audioOut, &ext->stoppedAtSamplePosition); // get final pos before we shut it down FskAudioNativePrintfVerbose("stoppedAtSamplePosition = %lld", ext->stoppedAtSamplePosition); audioOut->playing = false; FskAudioNativePrintfVerbose("-- stopping audioOut: %x", audioOut); res = (*ext->playItf)->SetPlayState(ext->playItf, SL_PLAYSTATE_STOPPED); CheckErr(" audioOutStop - set playstate stopped", res); if (gActiveAudioOut == audioOut) { FskMutexAcquire(gActiveAudioMutex); gActiveAudioOut = NULL; FskMutexRelease(gActiveAudioMutex); } androidAudioOutFlush(audioOut); bail: removeFromQueue(audioOut, kAll); return err; }
// --------------------------------------------------------------------- FskNetInterfaceRecord *FskNetInterfaceFindByName(char *name) { FskNetInterfaceRecord *ret = NULL, *found; FskInstrumentedTypePrintfDebug(&gNetInterfaceNotifierTypeInstrumentation, "FskNetInterfaceFindByName: %s", (name == NULL) ? "NULL" : name); FskMutexAcquire(gNetworkInterfaceList->mutex); found = (FskNetInterfaceRecord *)sFskNetInterfaceFindByName(name, (FskNetInterfaceRecord *)gNetworkInterfaceList->list); if (found) { if (kFskErrNone == FskMemPtrNewFromData(sizeof(FskNetInterfaceRecord), found, &ret)) { ret->next = NULL; ret->name = FskStrDoCopy(found->name); } } FskMutexRelease(gNetworkInterfaceList->mutex); return ret; }
void callVolumeNotifier(void *arg0, void *arg1, void *arg2, void *arg3) { FskFSVolumeNotifier volNtf = (FskFSVolumeNotifier)arg0; int mount = (int)arg1; int vid = (int)arg2; Boolean valid; FskAndroidFilesPrintfDebug("callVolumeNotifier\n"); FskMutexAcquire(gVolNotifiersMutex); valid = FskListContains(gVolNotifiers, offsetof(FskFSVolumeNotifierRecord, next) + (char*)volNtf); FskMutexRelease(gVolNotifiersMutex); if (!valid) return; FskAndroidFilesPrintfDebug("about to volNotifCallback %d for %d\n", mount, vid); (volNtf->callback)(mount, vid, volNtf->refCon); }
jint JAVANAME(FskView_setFskSurface)(JNIEnv* env, jobject viewObj, jobject surfaceObject) { int didLock; FskInstrumentedTypePrintfVerbose(&gAndroidWindowTypeInstrumentation, "gingerbread setFskSurface\n"); theNativeWindow = ANativeWindow_fromSurface(env, surfaceObject); if (!fbGlobals || !fbGlobals->frameBuffer) { FskInstrumentedTypePrintfMinimal(&gAndroidMainBlockTypeInstrumentation, "MDK - %p fbGlobals or ->frameBuffer %p is NULL here! -__ CHECK BAD BUILD\n", fbGlobals, fbGlobals ? fbGlobals->frameBuffer : 0); return kFskErrNone; } // was above the fbGlobals check - will we lose "surface" if we hit the case above? fbGlobals->surface = theNativeWindow; FskInstrumentedTypePrintfDebug(&gAndroidWindowTypeInstrumentation, "theNativeWindow/fbGlobals->surface is %p\n", theNativeWindow); didLock = (0 ==FskMutexTrylock(fbGlobals->screenMutex)); FskWindow win = FskWindowGetActive(); int invalidate = 0; if ((fbGlobals->frameBuffer->bounds.height != gScreenHeight) || (fbGlobals->frameBuffer->bounds.width != gScreenWidth)) { } else { FskInstrumentedTypePrintfVerbose(&gAndroidWindowTypeInstrumentation, "gingerbread setFskSurface - NOT about to copy from backing store (%d x %d).\n", fbGlobals->frameBuffer->bounds.width, fbGlobals->frameBuffer->bounds.height); invalidate = 1; } if (invalidate && win) { FskRectangleRecord b; FskPortGetBounds(win->port, &b); FskInstrumentedTypePrintfVerbose(&gAndroidWindowTypeInstrumentation, "gingerbread - invalidating port bounds %d %d %d %d\n", b.x, b.y, b.width, b.height); FskPortInvalidateRectangle(win->port, &b); } if (didLock) { FskInstrumentedTypePrintfVerbose(&gAndroidMainBlockTypeInstrumentation, "releasing from trylock\n"); FskMutexRelease(fbGlobals->screenMutex); } return 1; }
// This function will be called at a rate about (1000/updateInterval) void FskGtkWindowUpdateDa(FskGtkWindow win) { FskMutexAcquire(win->bufMutex); if(win->pixbufDraw) g_object_unref(win->pixbufDraw); win->pixbufDraw = gdk_pixbuf_copy(win->pixbuf); FskMutexRelease(win->bufMutex); g_async_queue_push(win->queue, win); #if 0 cairo_t *cr; cr = gdk_cairo_create (gtk_widget_get_window(win->da)); gdk_cairo_set_source_pixbuf(cr, win->pixbufDraw, 0, 0); cairo_paint(cr); cairo_destroy(cr); gtk_widget_queue_draw(win->window); #endif }
static Boolean sHaveNetworkInterfacesChanged() { FskErr err; Boolean retVal = false; FskNetInterfaceRecord *existing, *newer, *check; FskMutexAcquire(gNetworkInterfaceList->mutex); err = sFskNetInterfaceEnumerate(&newer); if (err) { retVal = true; goto done; } if (FskListCount(newer) != FskListCount(gNetworkInterfaceList->list)) { retVal = true; goto done; } check = newer; while (check) { Boolean gotOne = false; existing = (FskNetInterfaceRecord *)gNetworkInterfaceList->list; while (existing) { if (sCompareInterfaces(check, existing) == 0) { gotOne = true; break; } existing = existing->next; } if (!gotOne) { retVal = true; goto done; } check = check->next; } retVal = false; done: FskMutexRelease(gNetworkInterfaceList->mutex); sDisposeInterfaceList(&newer); return retVal; }
Boolean FskNetIsLocalNetwork(int addr) { FskNetInterfaceRecord *nir; Boolean ret = false; FskMutexAcquire(gNetworkInterfaceList->mutex); nir = (FskNetInterfaceRecord *)gNetworkInterfaceList->list; while (nir) { if ((0 != nir->ip) && ((nir->ip & nir->netmask) == (addr & nir->netmask))) { ret = true; goto done; } nir = nir->next; } done: FskMutexRelease(gNetworkInterfaceList->mutex); return ret; }
Boolean FskNetIsLocalAddress(int addr) { FskNetInterfaceRecord *nir; Boolean ret = false; if (0x7f000001 == addr) return true; FskMutexAcquire(gNetworkInterfaceList->mutex); nir = (FskNetInterfaceRecord *)gNetworkInterfaceList->list; while (nir) { if (nir->ip == addr) { ret = true; goto done; } nir = nir->next; } done: FskMutexRelease(gNetworkInterfaceList->mutex); return ret; }
jint JAVANAME(KinomaPlay_doResume)(JNIEnv* env, jclass clazz) { FskErr err = kFskErrNone; FskWindow fWin = FskWindowGetActive(); FskThread drawThread; FskInstrumentedTypePrintfVerbose(&gAndroidWindowTypeInstrumentation,"[%p] KinomaPlay_doResume(%p, %p, %p)", (void*)pthread_self(), env, clazz, fWin); BAIL_IF_NULL(fWin, err, kFskErrBadState); drawThread = fWin->thread; FskInstrumentedTypePrintfVerbose(&gAndroidWindowTypeInstrumentation, "KinomaPlay_doResume: drawThread is %p %s", drawThread, drawThread ? "" : ", bailing"); BAIL_IF_NULL(drawThread, err, kFskErrBadState); FskInstrumentedTypePrintfVerbose(&gAndroidWindowTypeInstrumentation, "KinomaPlay_doResume calling InitGLCallback"); FskMutexAcquire(jniRespMutex); err = FskThreadPostCallback(drawThread, InitGLCallback, theNativeWindow, NULL, NULL, NULL); if (!gQuitting) { FskConditionWait(jniRespCond, jniRespMutex); FskMutexRelease(jniRespMutex); } FskInstrumentedTypePrintfVerbose(&gAndroidWindowTypeInstrumentation, "KinomaPlay_doResume: FskThreadPostCallback(InitGLCallback) returns %d", err); FskInstrumentedTypePrintfVerbose(&gAndroidWindowTypeInstrumentation, "[%p] KinomaPlay_doResume successful", (void*)pthread_self()); bail: return !err; }
jint JAVANAME(FskViewGL_setFskSurface)(JNIEnv* env, jobject viewObj, jobject surfaceObj) { FskWindow fWin = FskWindowGetActive(); FskErr err = kFskErrNone; FskErr retErr; FskThread drawThread; FskInstrumentedTypePrintfVerbose(&gAndroidWindowTypeInstrumentation, "[%p] FskViewGL_setFskSurface(%p, %p, %p)", (void*)pthread_self(), env, viewObj, surfaceObj); ANativeWindow *nw = theNativeWindow; theNativeWindow = ANativeWindow_fromSurface(env, surfaceObj); fbGlobals->surface = theNativeWindow; if (theNativeWindow && theNativeWindow == nw) { FskInstrumentedTypePrintfVerbose(&gAndroidWindowTypeInstrumentation, " native window surface is same as before - don't setFskSurface twice\n"); return 0; } FskGLSetNativeWindow((void*)theNativeWindow); FskInstrumentedTypePrintfVerbose(&gAndroidWindowTypeInstrumentation, "FskViewGL_setFskSurface: active window is %p%s", fWin, fWin ? "" : ", bailing"); BAIL_IF_NULL(fWin, err, kFskErrBadState); drawThread = fWin->thread; FskInstrumentedTypePrintfVerbose(&gAndroidWindowTypeInstrumentation, "FskViewGL_setFskSurface: drawThread is %p %s", drawThread, drawThread ? "" : ", bailing"); BAIL_IF_NULL(drawThread, err, kFskErrBadState); FskInstrumentedTypePrintfVerbose(&gAndroidWindowTypeInstrumentation, "FskViewGL_setFskSurface calling InitGLCallback"); /* MDK - we need to wait for the callback to complete it's action in the other thread before we continue. I'm doing this by means of the jniRespCond. * However, at startup, we don't have the target thread to do it's work yet, so allow this through once at initialization. */ static int pass = 0; if (pass != 0) FskMutexAcquire(jniRespMutex); FskInstrumentedTypePrintfVerbose(&gAndroidMainBlockTypeInstrumentation, " about to post callback and wait for response from InitGLCallback\n"); err = FskThreadPostCallback(drawThread, InitGLCallback, theNativeWindow, NULL, NULL, NULL); if (pass++ != 0) { if (!gQuitting) { FskConditionWait(jniRespCond, jniRespMutex); FskMutexRelease(jniRespMutex); } } else usleep(500); FskInstrumentedTypePrintfVerbose(&gAndroidWindowTypeInstrumentation, "FskViewGL_setFskSurface: FskThreadPostCallback(InitGLCallback) returns %d", err); gScreenWidth = fbGlobals->frameBuffer->bounds.width; gScreenHeight = fbGlobals->frameBuffer->bounds.height; if (fWin) { FskRectangleRecord b; FskPortGetBounds(fWin->port, &b); FskInstrumentedTypePrintfVerbose(&gAndroidWindowTypeInstrumentation, " - gl invalidating port bounds %d %d %d %d\n", b.x, b.y, b.width, b.height); FskPortInvalidateRectangle(fWin->port, &b); } bail: return !err; }
// --------------------------------------------------------------------- static Boolean sNotifyNetworkInterfacesChanged() { FskErr err; Boolean retVal = false; FskNetInterfaceRecord *existing, *newer, *check, *old; #if SUPPORT_INSTRUMENTATION FskThread thread = FskThreadGetCurrent(); FskInstrumentedTypePrintfDebug(&gNetInterfaceNotifierTypeInstrumentation, "NotifyNetworkInterfacesChanged -- thread is: %x - %s", thread, thread->name); #endif /* SUPPORT_INSTRUMENTATION */ // If we fail to enumerate interfaces, assume there are no interfaces available now and // notify our clients that their interfaces have been removed. err = sFskNetInterfaceEnumerate(&newer); if (err) { FskInstrumentedTypePrintfDebug(&gNetInterfaceNotifierTypeInstrumentation, "NotifyNetworkInterfacesChanged -- can't enumerate, Down the interfaces"); FskMutexAcquire(gNetworkInterfaceList->mutex); existing = (FskNetInterfaceRecord *)gNetworkInterfaceList->list; while (existing) { sNotifyInterfaceNotifiers(existing, kFskNetInterfaceStatusRemoved); existing = existing->next; } sDisposeInterfaceList((FskNetInterfaceRecord**)(void*)&gNetworkInterfaceList->list); FskMutexRelease(gNetworkInterfaceList->mutex); return true; } FskMutexAcquire(gNetworkInterfaceList->mutex); old = (FskNetInterfaceRecord *)gNetworkInterfaceList->list; existing = (FskNetInterfaceRecord *)gNetworkInterfaceList->list; gNetworkInterfaceList->list = newer; while (existing) { FskInstrumentedTypePrintfDebug(&gNetInterfaceNotifierTypeInstrumentation, "NotifyNetworkInterfacesChanged -- looking for %s in the newer list", existing->name); check = sFskNetInterfaceFindByName(existing->name, newer); if (check) { FskInstrumentedTypePrintfDebug(&gNetInterfaceNotifierTypeInstrumentation, "NotifyNetworkInterfacesChanged -- found %s in the newer list", existing->name); if (sCompareInterfaces(check, existing) != 0) { FskInstrumentedTypePrintfDebug(&gNetInterfaceNotifierTypeInstrumentation, "NotifyNetworkInterfacesChanged -- %s changed - NOTIFY", existing->name); sNotifyInterfaceNotifiers(check, kFskNetInterfaceStatusChanged); } else { FskInstrumentedTypePrintfDebug(&gNetInterfaceNotifierTypeInstrumentation, "NotifyNetworkInterfacesChanged -- %s didn't change - no notify", existing->name); } } else { FskInstrumentedTypePrintfDebug(&gNetInterfaceNotifierTypeInstrumentation, "NotifyNetworkInterfacesChanged -- not found %s in the newer list - remove it.", existing->name); sNotifyInterfaceNotifiers(existing, kFskNetInterfaceStatusRemoved); } existing = existing->next; } existing = newer; while (existing) { check = sFskNetInterfaceFindByName(existing->name, old); if (!check) { FskInstrumentedTypePrintfDebug(&gNetInterfaceNotifierTypeInstrumentation, "NotifyNetworkInterfacesChanged -- new interface %s not in the older list - ADD it.", existing->name); sNotifyInterfaceNotifiers(existing, kFskNetInterfaceStatusNew); } existing = existing->next; } FskInstrumentedTypePrintfDebug(&gNetInterfaceNotifierTypeInstrumentation, "NotifyNetworkInterfacesChanged -- toss old list."); sDisposeInterfaceList(&old); existing = gNetworkInterfaceList->list; while (existing) { FskInstrumentedTypePrintfDebug(&gNetInterfaceNotifierTypeInstrumentation, " -- %s - %08x %08x %d", existing->name, existing->ip, existing->netmask, existing->status); existing = existing->next; } FskMutexRelease(gNetworkInterfaceList->mutex); return retVal; }
void gpioThread(void *param) { int seed = -1; struct pollfd *fds = NULL; int fdsInUse = 0; int pollersCount = 0; while (!gGPIOThreadQuit) { int result; linuxDigital walker; FskMutexAcquire(gLinuxDigitalPins->mutex); if (seed != gGPIOPollersSeed) { FskErr err; pollersCount = (int)FskListMutexCount(gLinuxDigitalPins); err = FskMemPtrRealloc((pollersCount + 1) * sizeof(struct pollfd), &fds); if (err) { FskMutexRelease(gLinuxDigitalPins->mutex); break; } seed = gGPIOPollersSeed; fds[0].fd = gGPIOEventFD; fds[0].events = POLLIN | POLLERR | POLLHUP; fdsInUse = 1; for (walker = (linuxDigital)gLinuxDigitalPins->list; NULL != walker; walker = *(linuxDigital *)walker) { linuxDigital w = (linuxDigital)(((char *)walker) - offsetof(linuxDigitalRecord, next)); if (w->canInterrupt && w->triggeredCallback) { fds[fdsInUse].fd = w->file; fds[fdsInUse].events = POLLPRI; fdsInUse += 1; } } } FskMutexRelease(gLinuxDigitalPins->mutex); result = poll(fds, fdsInUse, -1); if (fds[0].revents & POLLIN) { uint64_t ignore; read(gGPIOEventFD, &ignore, sizeof(ignore)); } FskMutexAcquire(gLinuxDigitalPins->mutex); for (walker = (linuxDigital)gLinuxDigitalPins->list; NULL != walker; walker = *(linuxDigital *)walker) { linuxDigital w = (linuxDigital)(((char *)walker) - offsetof(linuxDigitalRecord, next)); int i; struct pollfd *fdp = &fds[1]; for (i = 1; i < fdsInUse; i++, fdp++) { if ((fdp->fd == w->file) && (fdp->revents & POLLPRI)) { char buffer[6]; lseek(w->file, 0, SEEK_SET); read(w->file, buffer, sizeof(buffer) - 1); if (w->triggeredCallback) (w->triggeredCallback)((FskPinDigital)w, w->triggeredRefCon); break; } } } FskMutexRelease(gLinuxDigitalPins->mutex); } FskMemPtrDispose(fds); }
FskErr KprLibraryServerRequestConditionCallback(FskHTTPServerRequest request, UInt32 condition, void *refCon) { FskErr err = kFskErrNone; KprLibraryServer self = request->http->refCon; KprLibrarySession session = refCon; switch (condition) { case kFskHTTPConditionConnectionInitialized: case kFskHTTPConditionNoSocket: case kFskHTTPConditionRequestReceivedRequestHeaders: break; case kFskHTTPConditionRequestRequestFinished: { FskHeaders *headers; UInt32 queryIndex; KprLibraryQuery query; bailIfError(KprLibrarySessionNew(&session, request)); FskInstrumentedItemSetOwner(session, self); headers = FskHTTPServerRequestGetRequestHeaders(request); queryIndex = FskStrToNum(headers->filename); FskMutexAcquire(self->queryMutex); query = self->queries[queryIndex % kQueryCount]; if (query && (query->index == queryIndex)) { session->info = FskStrDoCopy(query->info); session->kind = query->kind; session->mime = FskStrDoCopy(query->mime); session->url = FskStrDoCopy(query->url); if (query->authorization) session->authorization = FskStrDoCopy(query->authorization); } else err = kFskErrNotFound; FskMutexRelease(self->queryMutex); if (kFskErrNone == err) { KprURLSplit(session->url, &session->parts); if (0 == FskStrCompareWithLength(session->url, "file", 4)) err = KprFileServerOpen(session); else if (0 == FskStrCompareWithLength(session->url, "http", 4)) { session->http.location = FskStrDoCopy(session->url); err = KprProxyServerOpen(session); } else err = KprDataServerOpen(session); } if (kFskErrNeedMoreTime == err) FskHTTPServerRequestSuspend(request); else session->error = err; err = kFskErrNone; } break; case kFskHTTPConditionRequestGenerateResponseHeaders: if (session) { FskHeaders *responseHeaders = FskHTTPServerRequestGetResponseHeaders(request); if (session->error) { if (kFskErrNotFound == session->error) responseHeaders->responseCode = 404; else responseHeaders->responseCode = 500; FskHeaderAddString(kFskStrContentLength, "0", responseHeaders); FskInstrumentedItemPrintfNormal(session, "response headers error %ld", session->error); } else if (session->file.file) KprFileServerGenerateResponseHeaders(session, responseHeaders); else if (session->http.client) KprProxyServerGenerateResponseHeaders(session, responseHeaders); else KprDataServerGenerateResponseHeaders(session, responseHeaders); } break; case kFskHTTPConditionConnectionTerminating: err = kFskErrUnimplemented; //@@ or hang on exit... weird. case kFskHTTPConditionRequestResponseFinished: case kFskHTTPConditionRequestErrorAbort: if (session) KprLibrarySessionDispose(session); break; default: err = kFskErrUnimplemented; break; } bail: return err; }