예제 #1
0
jint JAVANAME(FskViewGL_doFskSurfaceChanged)(JNIEnv* env, jobject viewObj, jint width, jint height) {
	int			retVal;
	FskGLPort	glPort = FskGLPortGetCurrent();

//FskThreadYield();
	FskInstrumentedTypePrintfVerbose(&gAndroidWindowTypeInstrumentation, "[%p] FskViewGL_doFskSurfaceChanged(%p, %p, %d, %d), port=%p", pthread_self(), env, viewObj, width, height, glPort);
	if (!glPort) {
		retVal = FskGLPortNew(width, height, viewObj, &glPort);
		switch (retVal) {
			case kFskErrNone:
				FskInstrumentedTypePrintfDebug(&gAndroidWindowTypeInstrumentation,"\tGL Port successfully created!");
				break;
			case kFskErrGraphicsContext:
				if (glPort) {
					FskInstrumentedTypePrintfDebug(&gAndroidWindowTypeInstrumentation, "\tCreated a new GL Port, but there is no EGL context; deferring initialization.");
					break;
				}
				/* fall through */
			default:
				FskInstrumentedTypePrintfDebug(&gAndroidWindowTypeInstrumentation, "\tCannot create a new GL Port(%d, %d) err = %d; create an EGL context first.", width, height, retVal);
				break;
		}
		if (glPort)
			FskGLPortSetCurrent(glPort);
	}
	FskInstrumentedTypePrintfDebug(&gAndroidWindowTypeInstrumentation, "\tFskViewGL_doFskSurfaceChanged calling FskView_doFskSurfaceChanged");
	retVal = JAVANAME(FskView_doFskSurfaceChanged)(env, viewObj, width, height);
	FskInstrumentedTypePrintfDebug(&gAndroidWindowTypeInstrumentation, "FskViewGL_doFskSurfaceChanged -- returning");
	return retVal;
}
예제 #2
0
FskErr RTPPacketBufferPushPacket( RTPPacketBuffer *buffer, RTPPacket packetIn )
{
	long   i;
	long   succeed = 0;
	FskErr err = 0;
	
	FskInstrumentedTypePrintfDebug(&gRTPPacketBufferTypeInstrumentation, "Push:: seq#:%d, last#: %d", packetIn->sequenceNumber, buffer->lastSequenceNumber);
	if( (SInt32)packetIn->sequenceNumber < buffer->lastSequenceNumber && buffer->lastSequenceNumber != -1 )
	{
		FskInstrumentedTypePrintfDebug(&gRTPPacketBufferTypeInstrumentation, "Push:: TOOOOOOOOOOO LAAAAAATE !!!!! seq#:%d#################################", packetIn->sequenceNumber);
	}

	for( i = 0; i < buffer->total; i++ )
	{
		RTPPacketBufferPacket    *thisPacket = &buffer->packets[i];

		if( thisPacket->isValid )
			continue;

		thisPacket->rtpPacket = packetIn;
		thisPacket->isValid = 1;
		succeed = 1;
		break;
	}

	if( succeed == 0 )
		err = -1;

	return err;
}
예제 #3
0
// ---------------------------------------------------------------------
void sNotifyInterfaceNotifiers(FskNetInterfaceRecord *iface, UInt32 status) {
	FskNetInterfaceNotifier callback = NULL, next;
	FskThread thread = FskThreadGetCurrent();

	callback = (FskNetInterfaceNotifier)FskListMutexGetNext(interfaceChangeCBList, NULL);
	while (callback) {
		next = (FskNetInterfaceNotifier)FskListMutexGetNext(interfaceChangeCBList, callback);
#if 0 && SUPPORT_INSTRUMENTATION
		if (FskInstrumentedItemHasListeners(callback)) {
			FskNetInterfaceRecord *iface = (FskNetInterfaceRecord *)FskNetInterfaceFindByName(ifcName);
			FskInterfaceInstrData data;
			data.notf = callback;
			data.ifc = iface;
			data.status = status;
			FskInstrumentedItemSendMessage(callback, kFskNetInstrMsgInterfaceNotify, &data);
		}
#endif /* SUPPORT_INSTRUMENTATION */
		if (callback->thread != thread) {
			FskNetInterfaceRecord *interFace;
			if (kFskErrNone == FskMemPtrNewFromData(sizeof(FskNetInterfaceRecord), iface, &interFace)) {
				interFace->next = NULL;
				interFace->name = FskStrDoCopy(iface->name);

				// POST notify
				FskInstrumentedTypePrintfDebug(&gNetInterfaceNotifierTypeInstrumentation, " - posting callback to thread %s for interface %s", callback->thread->name, iface->name);
				FskThreadPostCallback(callback->thread, doNetIfcCallback, (void*)callback->callback, (void*)interFace, (void*)status, (void*)callback->param);
			}
		}
		else {
			FskInstrumentedTypePrintfDebug(&gNetInterfaceNotifierTypeInstrumentation, "callback->thread %s - call", callback->thread->name);
			(callback->callback)(iface, status, callback->param);
		}
		callback = next;
	}
}
예제 #4
0
// ---------------------------------------------------------------------
void doNetIfcCallback(void *a, void *b, void *c, void *d) {
	FskNetInterfaceChangedCallback callback = (FskNetInterfaceChangedCallback)a;
	FskNetInterfaceRecord *iface = (FskNetInterfaceRecord *)b;
	UInt32 status = (UInt32)c;
	void *param = (void*)d;

	callback(iface, status, param);
	FskInstrumentedTypePrintfDebug(&gNetInterfaceNotifierTypeInstrumentation, "doNetIfcCallback - about to dispose description");
	FskNetInterfaceDescriptionDispose(iface);
	FskInstrumentedTypePrintfDebug(&gNetInterfaceNotifierTypeInstrumentation, "doNetIfcCallback - after disposing description");
}
예제 #5
0
static void sFskHandleNetworkInterfacesChanged() {
#if SUPPORT_INSTRUMENTATION
	FskThread thread = FskThreadGetCurrent();
	FskInstrumentedTypePrintfDebug(&gNetInterfaceNotifierTypeInstrumentation, "Interfaces changed -- thread is: %x - %s", thread, thread->name);
#endif /* SUPPORT_INSTRUMENTATION */

	if (sHaveNetworkInterfacesChanged()) {
		FskInstrumentedTypePrintfDebug(&gNetInterfaceNotifierTypeInstrumentation, "Interfaces have changed - about to call notify");
		sNotifyNetworkInterfacesChanged();
		FskInstrumentedTypePrintfDebug(&gNetInterfaceNotifierTypeInstrumentation, "Interfaces have changed - after calling notify");
	}
}
예제 #6
0
FskErr _PushDataToLinkedFrames( int size, unsigned char *dataPtr, RTPCompressedMediaFrame *storedFrames )
{
	RTPCompressedMediaFrame	frame = NULL;
	UInt32					err   = 0;

	err	= FskMemPtrNewClear( size + sizeof(RTPCompressedMediaFrameRecord), &frame);
	if (0 != err) goto bail;

	frame->next		= NULL;
	frame->length	= size;
	FskMemMove( frame + 1, dataPtr, size );		

	// Add the current buffer to our link list
	if( (*storedFrames) == NULL )
		*storedFrames = frame;
	else 
	{
		RTPCompressedMediaFrame  currentFrames = *storedFrames;

		while( currentFrames->next != NULL )
			currentFrames = currentFrames->next;

		currentFrames->next = frame;
	}

	FskInstrumentedTypePrintfDebug(&gRTPPacketParserH263TypeInstrumentation, "						append: %d", size);

bail:
	if( err != 0  && frame != NULL )
		FskMemPtrDispose(frame);

	return err;
}
예제 #7
0
FskErr _MoveLinkedFramesDataToFrame( RTPCompressedMediaFrame storedFrames, RTPCompressedMediaFrame frame )
{
	int				copiedSize = 0;
	unsigned char	*pData = NULL;
	
	frame->next	= NULL;
	
	// Walk our list again and really prepend the data
	pData = (unsigned char *)( frame + 1 ); // Move pass the header
	
	while(storedFrames)
	{
		RTPCompressedMediaFrame currStoredFrames = storedFrames;
		UInt32					currStoredSize	 = storedFrames->length;
		
		FskMemMove(pData, storedFrames+1, currStoredSize);
		storedFrames = storedFrames->next;
		
		// Remove our stored data from our list
		FskMemPtrDispose(currStoredFrames);
		currStoredFrames = NULL;
		
		// increment our frame ptr
		pData += currStoredSize;
		copiedSize += currStoredSize;
	}

	frame->length	= copiedSize;

	FskInstrumentedTypePrintfDebug(&gRTPPacketParserH263TypeInstrumentation, "						_MoveLinkedFramesDataToFrame: %d", frame->length);

	return 0;
}
예제 #8
0
FskHTTPServerListener FskHTTPServerListenerNew(FskHTTPServer http, int port, char *interfaceName) {
	FskHTTPServerListener	listener;
	FskErr			err;
	FskSocket		skt;
	FskNetInterfaceRecord *ifc = NULL;

	FskInstrumentedTypePrintfDebug(&gFskHTTPServerTypeInstrumentation, "httpServerListenerNew - interfaceName: %s\n", interfaceName);
	err = FskMemPtrNewClear(sizeof(FskHTTPServerListenerRecord), (FskMemPtr*)&listener);
	BAIL_IF_ERR(err);
	listener->http = http;
	listener->port = port;
	listener->ifcName = FskStrDoCopy(interfaceName);
	err = FskNetSocketNewTCP(&skt, true, "HTTP Server");
	if (err) {
		FskInstrumentedItemSendMessage(listener->http, kFskHTTPInstrMsgErrString, "listener socket create failed.");
		FskInstrumentedTypePrintfDebug(&gFskHTTPServerTypeInstrumentation, "httpServerListenerNew -  creating socket failed: %d\n", err);
        BAIL(kFskErrNoMoreSockets);
	}
	FskNetSocketReuseAddress(skt);
	ifc = FskNetInterfaceFindByName(listener->ifcName);
	if ((NULL == ifc) ||
		(kFskErrNone != (err = FskNetSocketBind(skt, ifc->ip, listener->port)))) {
		FskNetSocketClose(skt);
		FskInstrumentedTypePrintfDebug(&gFskHTTPServerTypeInstrumentation, "httpServerListenerNew - bind failed: %d port: %d\n", err, listener->port);
		listener->http->stats.connectionsAborted++;
		if (listener->http->callbacks)
			err = doCallCondition(listener->http->callbacks->serverCondition, listener->http, kFskHTTPConditionNoSocket, listener->http->refCon);
		goto bail;
	}

	listener->skt = skt;	
	FskNetSocketMakeNonblocking(skt);
	FskListAppend((FskList*)&listener->http->listeners, listener);
	FskInstrumentedTypePrintfDebug(&gFskHTTPServerTypeInstrumentation, "httpServerListenerNew -  about to listen\n");

	FskNetSocketListen(skt);
	FskThreadAddDataHandler(&listener->dataHandler, (FskThreadDataSource)skt, (FskThreadDataReadyCallback)httpServerListenerAcceptNewConnection, true, false, listener);

	FskInstrumentedItemSendMessage(listener->http, kFskHTTPInstrMsgNowListening, listener);
bail:
	FskNetInterfaceDescriptionDispose(ifc);
	if (err) {
		FskInstrumentedItemSendMessage(listener->http, kFskHTTPInstrMsgFailedListener, listener);
		FskMemPtrDisposeAt((void**)&listener);
	}
	return listener;
}
예제 #9
0
FskErr FskHTTPServerListenerAdd(FskHTTPServer http, int port, char *ifcName, FskHTTPServerListener *newListener) {
	FskHTTPServerListener listener;
	FskErr err = kFskErrNone;

	FskInstrumentedTypePrintfDebug(&gFskHTTPServerTypeInstrumentation, "httpServerListenerAdd - ifcName: %s\n", ifcName);
	listener = FskHTTPServerListenerNew(http, port, ifcName);
	if (!listener) {
		FskInstrumentedTypePrintfDebug(&gFskHTTPServerTypeInstrumentation, "httpServerListenerAdd - no listener created\n");
		err = kFskErrOperationFailed;
	}

	if (newListener)
		*newListener = listener;

		FskInstrumentedTypePrintfDebug(&gFskHTTPServerTypeInstrumentation, "httpServerListenerAdd - %s:%d returns %d\n", ifcName, port, err);
	return err;
}
예제 #10
0
void FskGtkWindowInvalidDaRect(FskGtkWindow win, FskRectangle area)
{
	if(win->menuStatus == false)
		return;

	FskInstrumentedTypePrintfDebug(&gFskGtkWindowTypeInstrumentation, "Tell GTK window to redraw in FskGtkWindowInvalidDaRect");
	gtk_widget_queue_draw(GTK_WIDGET(win->da));
}
예제 #11
0
FskErr FskHTTPServerListenerDispose(FskHTTPServerListener listener) {
	FskInstrumentedTypePrintfDebug(&gFskHTTPServerTypeInstrumentation, "httpServerListenerDispose - listener: %p\n", listener);
	if (listener) {
		if (listener->http && listener->http->listeners)
			FskListRemove((FskList*)&listener->http->listeners, listener);
		if (listener->handshaking) {
			FskInstrumentedTypePrintfDebug(&gFskHTTPServerTypeInstrumentation, "httpServerListenerDispose - listener: %p - wait for handshaking\n", listener);
			listener->http = NULL;
		}
		else {
			FskThreadRemoveDataHandler(&listener->dataHandler);
			FskNetSocketClose(listener->skt);
			FskMemPtrDispose(listener->ifcName);
			FskMemPtrDispose(listener);
		}
	}
	return kFskErrNone;
}
예제 #12
0
void sFskHTTPServerDownUse(FskHTTPServer http) {
	FskInstrumentedTypePrintfDebug(&gFskHTTPServerTypeInstrumentation, "%p ServerDownUse to %d\n", http, http ? http->useCount : 0);
	if (NULL != http) {
		http->useCount--;
		if (http->useCount == 0) {
			sFskHTTPServerDispose(http);
		}
	}
}
예제 #13
0
void sFskHTTPServerRequestDownUse(FskHTTPServerRequest request) {
	FskInstrumentedTypePrintfDebug(&gFskHTTPServerTypeInstrumentation, "%p ServerRequestDownUse to %d\n", request, request ? request->useCount : 0);
	if (NULL != request) {
		request->useCount--;
		if (request->useCount == 0) {
			sFskHTTPServerRequestDispose(request);
		}
	}
}
예제 #14
0
// Event handler: da->draw
static gboolean draw_callback(GtkWidget *widget, cairo_t *cr, gpointer data)
{
	FskInstrumentedTypePrintfDebug(&gFskGtkWindowTypeInstrumentation, "Firing draw callback!!!");
	FskGtkWindow win = (FskGtkWindow)data;

	if(win->pixbuf)
		gdk_cairo_set_source_pixbuf(cr, win->pixbuf, 0, 0);
	cairo_paint(cr);

	return TRUE;
}
예제 #15
0
void sFskHTTPServerRequestDispose(FskHTTPServerRequest request) {
	FskInstrumentedTypePrintfDebug(&gFskHTTPServerTypeInstrumentation, "sFskHTTPServerRequestDispose %p  - useCount: %d\n", request, request ? request->useCount : 0);
	if (!request)
		return;

	FskInstrumentedItemDispose(request);
	FskNetSocketClose(request->skt);
	FskHeaderStructDispose(request->requestHeaders);
	FskHeaderStructDispose(request->responseHeaders);
	FskMemPtrDispose(request->in.buf);
	FskMemPtrDispose(request->out.buf);
	FskMemPtrDispose(request);
}
예제 #16
0
void FskNetInterfaceRemoveNotifier(FskNetInterfaceNotifier callbackRef)
{
//	FskThread thread = FskThreadGetCurrent();

//	FskInstrumentedTypePrintfDebug(&gNetInterfaceNotifierTypeInstrumentation, "NetInterfaceNotifier REMOVE -- %x", callbackRef);
	if (NULL != callbackRef) {
		FskInstrumentedTypePrintfDebug(&gNetInterfaceNotifierTypeInstrumentation, "NetInterface REMOVE -- %x %s", callbackRef, callbackRef->name);
		FskListMutexRemove(interfaceChangeCBList, callbackRef);
		FskInstrumentedItemDispose(callbackRef);
		FskMemPtrDispose(callbackRef);
	}
//	FskInstrumentedTypePrintfDebug(&gNetInterfaceNotifierTypeInstrumentation, "NetInterface REMOVE -- %x done", callbackRef);
}
예제 #17
0
void httpServerInterfaceDown(FskHTTPServer http, char *ifcName) {
	FskHTTPServerListener cur = http->listeners, next = NULL;

	FskInstrumentedTypePrintfDebug(&gFskHTTPServerTypeInstrumentation, "httpServerInterfaceDown - ifcName: %p\n", ifcName);
	if (ifcName == NULL) return;

	while (cur) {
		next = cur->next;
		if (0 == FskStrCompare(cur->ifcName, ifcName)) {
			FskHTTPServerListenerDispose(cur);
		}
		cur = next;
	}
}
예제 #18
0
void FskHTTPServerRequestDispose(FskHTTPServerRequest request) {
	FskInstrumentedTypePrintfDebug(&gFskHTTPServerTypeInstrumentation, "FskHTTPServerRequestDispose %p  - useCount: %d\n", request, request ? request->useCount : 0);
	if (request) {
		FskTimeCallbackDispose(request->timer);
		FskListRemove((FskList*)&request->http->activeRequests, request);
		FskThreadRemoveDataHandler(&request->dataHandler);
		FskTimeCallbackDispose(request->cycleCallback);
		request->cycleCallback = NULL;
		FskTimeCallbackDispose(request->keepAliveKillCallback);
		request->keepAliveKillCallback = NULL;
		request->keepAliveTimeout = 0;
		request->http->stats.connectionsCompleted++;
		sFskHTTPServerRequestDownUse(request);
	}
}
예제 #19
0
// This function will be called at a rate about (1000/updateInterval)
void FskGtkWindowUpdateDa(FskGtkWindow win)
{
	if(win->menuStatus == false)
		return;

	FskInstrumentedTypePrintfDebug(&gFskGtkWindowTypeInstrumentation, "Tell GTK window to redraw in FskGtkWindowUpdateDa");
	gtk_widget_queue_draw(GTK_WIDGET(win->da));
#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
}
예제 #20
0
FskErr _GetLinkededFramesSize( RTPCompressedMediaFrame storedFrames, UInt32	*storedSizeOut )
{
	UInt32	storedSize		= 0;
	
	// if we have saved data, get it and prepend it to the current data
	while(storedFrames)
	{
		storedSize += storedFrames->length;
		storedFrames = storedFrames->next;
	}

	*storedSizeOut = storedSize;

	FskInstrumentedTypePrintfDebug(&gRTPPacketParserH263TypeInstrumentation, "						_GetLinkededFramesSize: %d", storedSize);

	return 0;
}
예제 #21
0
// ---------------------------------------------------------------------
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;
}
예제 #22
0
/*
 	interface is optional. If NULL, then all interfaces will be used
*/
FskErr FskHTTPServerCreate(int port, char *interfaceName, FskHTTPServer *server, void *refCon, Boolean ssl) {
	FskHTTPServer	http;
	FskErr err;

	FskInstrumentedTypePrintfDebug(&gFskHTTPServerTypeInstrumentation, "httpServerCreate\n");
	err = FskMemPtrNewClear(sizeof(FskHTTPServerRecord), (FskMemPtr*)&http);
	BAIL_IF_ERR(err);

	sFskHTTPServerUpUse(http);

	http->stopped = true;
	http->refCon = refCon;
	http->port = port;
	http->keepAliveTimeout = kFskHTTPKeepAliveTimeout;
	http->defaultBufferSize = kFskHTTPServerDefaultBufferSize;
	http->owner = FskThreadGetCurrent();
	http->ssl = ssl;

	snprintf(http->name, 64, "%s:%d", interfaceName ? interfaceName : "all", port);
	FskInstrumentedItemNew(http, http->name, &gFskHTTPServerTypeInstrumentation);

	if (interfaceName) {
		err = FskHTTPServerListenerAdd(http, port, interfaceName, NULL);
	}
	else {
		FskNetInterfaceRecord *ifc;
		int i, numI;
		http->all = true;
		numI = FskNetInterfaceEnumerate();
		for (i=0; i<numI; i++) {
			FskErr notErr = FskNetInterfaceDescribe(i, &ifc);
			if (notErr) continue;
			if (ifc->status) {
				notErr = FskHTTPServerListenerAdd(http, port, ifc->name, NULL);
				if (notErr) err = notErr;
			}
			FskNetInterfaceDescriptionDispose(ifc);
		}
	}

	http->interfaceNotifier = FskNetInterfaceAddNotifier(httpServerInterfaceChanged, http, "http server");

bail:
	*server = http;
	return err;
}
예제 #23
0
FskErr _ClearLinkedFrames( RTPCompressedMediaFrame storedFrames )
{
	while(storedFrames)
	{
		RTPCompressedMediaFrame currStoredFrames = storedFrames;
		
			storedFrames = storedFrames->next;
		
		// Remove our stored data from our list
		FskMemPtrDispose(currStoredFrames);
		currStoredFrames = NULL;
	}

	FskInstrumentedTypePrintfDebug(&gRTPPacketParserH263TypeInstrumentation, "						_ClearLinkedFrames");

	return 0;
}
예제 #24
0
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;
}
예제 #25
0
jint
JAVANAME(FskView_unsetFskSurface)(JNIEnv* env, jobject viewObj) {
	FskBitmap fb;
	FskInstrumentedTypePrintfVerbose(&gAndroidWindowTypeInstrumentation, "gingerbread FskView_unsetFskSurface -- fbGlobals->surface is %p\n", fbGlobals->surface);

	if (fbGlobals->surface == NULL)
		return 0;

	FskECMAScriptHibernate();

	FskInstrumentedTypePrintfDebug(&gAndroidWindowTypeInstrumentation, "unsetFskSurface - about to release theNativeWindow %p\n", theNativeWindow);
	if (theNativeWindow)
		ANativeWindow_release(theNativeWindow);

	fbGlobals->surface = NULL;
	theNativeWindow = NULL;

	return 1;
}
예제 #26
0
FskErr FskHTTPServerDispose(FskHTTPServer http) {
	FskInstrumentedTypePrintfDebug(&gFskHTTPServerTypeInstrumentation, "FskHTTPServerDispose %p  - useCount: %d\n", http, http ? http->useCount : 0);
	if (http) {
		// remove existing requests
		while (http->activeRequests) {
			FskHTTPServerRequest request = http->activeRequests;
			FskInstrumentedItemSendMessage(request, kFskHTTPInstrMsgRequestRemainsOnClose, request);
			if (kFskErrNone != doCallCondition(http->callbacks->requestCondition, request, kFskHTTPConditionConnectionTerminating, request->refCon))
				FskHTTPServerRequestDispose(request);
		}

		FskNetInterfaceRemoveNotifier(http->interfaceNotifier);
		while (http->listeners)
			FskHTTPServerListenerDispose(http->listeners);

		sFskHTTPServerDownUse(http);
	}
	return kFskErrNone;
}
예제 #27
0
FskNetInterfaceNotifier FskNetInterfaceAddNotifier(FskNetInterfaceChangedCallback callback, void *param, char *debugName)
{
	FskNetInterfaceNotifier notRef = NULL;
	FskThread thread = FskThreadGetCurrent();
	UInt32 nameLen = debugName ? FskStrLen(debugName) + 1 : 0;

	if (kFskErrNone == FskMemPtrNewClear(sizeof(FskNetInterfaceNotifierRec) + nameLen, &notRef)) {
		FskInstrumentedTypePrintfDebug(&gNetInterfaceNotifierTypeInstrumentation, "NetInterfaceNotifier NEW -- %x", notRef);
		notRef->callback = callback;
		notRef->param = param;

		notRef->thread = thread;
		if (nameLen)
			FskMemMove(notRef->name, debugName, nameLen);

		FskListMutexPrepend(interfaceChangeCBList, notRef);
		FskInstrumentedItemNew(notRef, notRef->name, &gNetInterfaceNotifierTypeInstrumentation);
	}
	return notRef;
}
예제 #28
0
void printInterfaces() {
	FskNetInterfaceRecord *nir;
	char str[32], mac[32];
	nir = gNetworkInterfaces;
	while (nir) {
		FskNetIPandPortToString(nir->ip, 0, str);
		FskStrNumToHex(nir->MAC[0], mac, 2);
		mac[2] = ':';
		FskStrNumToHex(nir->MAC[1], &mac[3], 2);
		mac[5] = ':';
		FskStrNumToHex(nir->MAC[2], &mac[6], 2);
		mac[8] = ':';
		FskStrNumToHex(nir->MAC[3], &mac[9], 2);
		mac[11] = ':';
		FskStrNumToHex(nir->MAC[4], &mac[12], 2);
		mac[14] = ':';
		FskStrNumToHex(nir->MAC[5], &mac[15], 2);
		mac[17] = '\0';

		FskInstrumentedTypePrintfDebug(&gNetInterfaceNotifierTypeInstrumentation, "IFC: %s -- %s -- %s", nir->name, str, mac);
		nir = nir->next;
	}
}
예제 #29
0
static FskErr sFskNetInterfaceEnumerate(FskNetInterfaceRecord **interfaceList)
{
	FskErr	err = kFskErrNone;
	FskNetInterfaceRecord *nir;
	int fd;
	struct ifreq  ifr;
	struct sockaddr_in *sa;
#if TARGET_OS_MAC	// BSD
	struct ifreq ibuf[32];
#endif /* TARGET_OS_MAC */
#if TARGET_OS_LINUX
#if TARGET_OS_ANDROID
	DIR *d;
	struct dirent *dir;
	*interfaceList = NULL;

	fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
	if (fd < 0) goto skip;

	FskInstrumentedTypePrintfDebug(&gNetInterfaceNotifierTypeInstrumentation, "Enumerate Interfaces:");

	d = opendir("/sys/class/net");
	if (0 == d)  {
		BAIL(kFskErrNetworkInterfaceError);
	}

	while ((dir = readdir(d))) {
#if IGNORE_NETINTERFACE
		Boolean ignore = false;
		int i;
#endif
		char *ifname;
		unsigned theIP = 0, theNetmask = 0, theStatus = 0;

		if (dir->d_name[0] == '.')
			continue;

		ifname = dir->d_name;

		FskInstrumentedTypePrintfDebug(&gNetInterfaceNotifierTypeInstrumentation,"%s: ", ifname);

#if IGNORE_NETINTERFACE
		i = NUM_IGNORE_NET;
		while (i) {
			if (FskStrCompare(ignoreInterfaces[i-1], ifname) == 0) {
				FskInstrumentedTypePrintfDebug(&gNetInterfaceNotifierTypeInstrumentation, "IGNORED");
				ignore = true;
			}
			i--;
		}
		if (ignore)
			continue;
#endif /* IGNORE_NETINTERFACE */

		memset(&ifr, 0,  sizeof(struct ifreq));
		strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
		ifr.ifr_name[IFNAMSIZ - 1] = 0;

		if (ioctl(fd, SIOCGIFADDR, &ifr) >= 0) {
			sa = (struct sockaddr_in*)(void*)&(ifr.ifr_addr);
			theIP = ntohl( sa->sin_addr.s_addr);
		}

		if (ioctl(fd, SIOCGIFNETMASK, &ifr) >= 0) {
			sa = (struct sockaddr_in*)(void*)&(ifr.ifr_addr);
			theNetmask = ntohl( sa->sin_addr.s_addr);
		}

		if (ioctl(fd, SIOCGIFFLAGS, &ifr) >= 0) {
			if (ifr.ifr_flags & 1)
				theStatus = 1;
		}

		if (theIP == 0)
			theStatus = 0;

		FskInstrumentedTypePrintfDebug(&gNetInterfaceNotifierTypeInstrumentation,"IP: %x, Netmask: %x [%s]", theIP, theNetmask, theStatus ? "UP " : "DOWN ");

		if (ioctl(fd, SIOCGIFHWADDR, &ifr) >= 0) {
			FskInstrumentedTypePrintfDebug(&gNetInterfaceNotifierTypeInstrumentation, "Got HWADDR ");

			if (ifr.ifr_hwaddr.sa_family == ARPHRD_ETHER) {
				FskInstrumentedTypePrintfDebug(&gNetInterfaceNotifierTypeInstrumentation, " ETHER");
				FskMemPtrNewClear(sizeof(FskNetInterfaceRecord), (FskMemPtr*)(void*)&nir);
				if (!nir) {
					closedir(d);
					BAIL(kFskErrMemFull);
				}
				FskMemCopy(nir->MAC, ifr.ifr_hwaddr.sa_data, 6);

				nir->name = FskStrDoCopy(ifname);
				nir->ip = theIP;
				nir->netmask = theNetmask;
				nir->status = theStatus;

				FskListAppend((FskList*)interfaceList, nir);
			}
			else {
				FskInstrumentedTypePrintfDebug(&gNetInterfaceNotifierTypeInstrumentation, " Family not ETHER Huh?");
			}
		}
	}
	closedir(d);
skip:

#else /* !TARGET_OS_ANDROID */
	FILE *fp;
	char buf[256];
#if IGNORE_NETINTERFACE
	Boolean ignore = false;
	int i;
#endif

	*interfaceList = NULL;
	fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
	if (fd < 0) goto skip;

	fp = fopen("/proc/net/dev", "r");
	if (!fp) {
		BAIL(kFskErrNetworkInterfaceError);
	}
	// ignore two lines
	fgets(buf, sizeof(buf), fp);
	fgets(buf, sizeof(buf), fp);
	while (fgets(buf, sizeof(buf), fp)) {
		char *ifname = strtok(buf, " :");
		if (!ifname) continue;

		FskInstrumentedTypePrintfDebug(&gNetInterfaceNotifierTypeInstrumentation,"%s: ", ifname);

#if IGNORE_NETINTERFACE
		i = NUM_IGNORE_NET;
		while (i) {
			if (FskStrCompare(ignoreInterfaces[i-1], ifname) == 0) {
				FskInstrumentedTypePrintfDebug(&gNetInterfaceNotifierTypeInstrumentation, "IGNORED");
				ignore = true;
			}
			i--;
		}
		if (ignore)
			continue;
#endif /* IGNORE_NETINTERFACE */
		strcpy(ifr.ifr_name, ifname);
		if ((ioctl(fd, SIOCGIFHWADDR, &ifr) != -1) && (ifr.ifr_hwaddr.sa_family == ARPHRD_ETHER)) {
			FskMemPtrNewClear(sizeof(FskNetInterfaceRecord), (FskMemPtr *)&nir);
			if (!nir) {
				err = kFskErrMemFull;
				fclose(fp);
				goto bail;
			}
			FskMemCopy(nir->MAC, ifr.ifr_hwaddr.sa_data, 6);
			nir->name = FskStrDoCopy(ifname);

			nir->ip = 0;
			if (ioctl(fd, SIOCGIFADDR, &ifr) != -1) {
				sa = (struct sockaddr_in*)(void*)&(ifr.ifr_addr);
				nir->ip = ntohl( sa->sin_addr.s_addr);
			}

			if (ioctl(fd, SIOCGIFNETMASK, &ifr) != -1) {
				sa = (struct sockaddr_in*)(void*)&(ifr.ifr_addr);
				nir->netmask = ntohl( sa->sin_addr.s_addr);
			}

			if (ioctl(fd, SIOCGIFFLAGS, &ifr) != -1) {
				if (ifr.ifr_flags & IFF_UP) {
					nir->status = 1;
				} else {
					nir->status = 0;
				}
			}

			if (nir->ip == 0)
				nir->status = 0;

			FskInstrumentedTypePrintfDebug(&gNetInterfaceNotifierTypeInstrumentation,"IP: %x, Netmask: %x [%s] HWADDR [%02x:%02x:%02x:%02x:%02x:%02x]", theIP, theNetmask, theStatus ? "UP " : "DOWN ", nir->MAC[0], nir->MAC[1], nir->MAC[2], nir->MAC[3], nir->MAC[4], nir->MAC[5]);
			FskListAppend((FskList*)interfaceList, nir);
		}
		else {
			FskInstrumentedTypePrintfDebug(&gNetInterfaceNotifierTypeInstrumentation, " Family not ETHER or no HWADDR");
		}
	}
	fclose(fp);
skip:
#endif /* !TARGET_OS_ANDROID */

#elif TARGET_OS_MAC && !TARGET_OS_IPHONE
	struct ifreq *ifrp, *ifend;
	unsigned int r;
	struct ifconf ifc;
#if IGNORE_NETINTERFACE
	Boolean ignore = false;
	int i;
#endif

	*interfaceList = NULL;
	fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
	ifc.ifc_len = sizeof(ibuf);
	ifc.ifc_buf = (caddr_t)ibuf;
	if (ioctl(fd, SIOCGIFCONF, &ifc) == -1 ||
		ifc.ifc_len < (int)sizeof(struct ifreq)) {
		BAIL(kFskErrNetworkInterfaceError);
	}

	ifrp = ibuf;
	ifend = (struct ifreq*)((char*)ibuf + ifc.ifc_len);
	while (ifrp < ifend) {
		if (ifrp->ifr_addr.sa_family == AF_LINK &&
			((struct sockaddr_dl *)&ifrp->ifr_addr)->sdl_type == IFT_ETHER) {
			err = FskMemPtrNewClear(sizeof(FskNetInterfaceRecord), (FskMemPtr *)&nir);
			BAIL_IF_ERR(err);
			nir->name = FskStrDoCopy(ifrp->ifr_name);
			FskMemCopy((char*)nir->MAC, (char*)LLADDR((struct sockaddr_dl *)&ifrp->ifr_addr), 6);

			FskInstrumentedTypePrintfDebug(&gNetInterfaceNotifierTypeInstrumentation,"%s: ", nir->name);

#if IGNORE_NETINTERFACE
			i = NUM_IGNORE_NET;
			ignore = false;
			while (i) {
				if (FskStrCompare(ignoreInterfaces[i-1], nir->name) == 0) {
					FskInstrumentedTypePrintfDebug(&gNetInterfaceNotifierTypeInstrumentation, "IGNORED");
					ignore = true;
				}
				i--;
			}
			if (ignore) {
				FskMemPtrDispose(nir->name);
				FskMemPtrDisposeAt(&nir);
				goto nextOne;
			}
#endif /* IGNORE_NETINTERFACE */

			strcpy(ifr.ifr_name, nir->name);		//@@ bounds check needed?
			if (ioctl(fd, SIOCGIFADDR, &ifr) != -1) {
				sa = (struct sockaddr_in*)(void*)&(ifr.ifr_addr);
				nir->ip = ntohl( sa->sin_addr.s_addr);
			}
			if (nir->ip) {
				if (ioctl(fd, SIOCGIFNETMASK, &ifr) != -1) {
					sa = (struct sockaddr_in*)(void*)&(ifr.ifr_addr);
					nir->netmask = ntohl( sa->sin_addr.s_addr);
				}

				if (ioctl(fd, SIOCGIFFLAGS, &ifr) != -1) {
					if (ifr.ifr_flags & IFF_UP)
						nir->status = 1;
				}

				FskInstrumentedTypePrintfDebug(&gNetInterfaceNotifierTypeInstrumentation,"IP: %x, Netmask: %x [%s] HWADDR [%02x:%02x:%02x:%02x:%02x:%02x]", nir->ip, nir->netmask, nir->status ? "UP " : "DOWN ", nir->MAC[0], nir->MAC[1], nir->MAC[2], nir->MAC[3], nir->MAC[4], nir->MAC[5]);

				FskListAppend(interfaceList, nir);
			}
			else {
				FskMemPtrDispose(nir->name);
				FskMemPtrDisposeAt(&nir);
			}
		}

nextOne:
		r = ifrp->ifr_addr.sa_len + sizeof(ifrp->ifr_name);
		if (r < sizeof(*ifrp))
			r = sizeof(*ifrp);
		ifrp = (struct ifreq*)((char*)ifrp+r);
	}

#elif TARGET_OS_IPHONE
	struct ifaddrs *iflist;
	if (getifaddrs(&iflist) != 0)
		return kFskErrNetworkInterfaceError;
	*interfaceList = NULL;
	for (struct ifaddrs *ifa = iflist; ifa != NULL; ifa = ifa->ifa_next) {
		if (ifa->ifa_name == NULL || ifa->ifa_addr == NULL || ifa->ifa_netmask == NULL || ((struct sockaddr_in*)(void*)ifa->ifa_addr)->sin_addr.s_addr == 0)
			continue;
		for (FskNetInterface ni = *interfaceList; ni != NULL; ni = ni->next) {
			if (FskStrCompare(ni->name, ifa->ifa_name) == 0)
				goto next;
		}
		if ((err = FskMemPtrNewClear(sizeof(FskNetInterfaceRecord), (FskMemPtr *)&nir)) != kFskErrNone)
			return err;
		nir->name = FskStrDoCopy(ifa->ifa_name);
		nir->ip = ntohl(((struct sockaddr_in*)(void*)ifa->ifa_addr)->sin_addr.s_addr);
		nir->netmask = ntohl(((struct sockaddr_in*)(void*)ifa->ifa_netmask)->sin_addr.s_addr);
		nir->status = ifa->ifa_flags & IFF_UP ? 1 : 0;
		FskListAppend((FskList *)interfaceList, nir);
	next:;
	}
	freeifaddrs(iflist);
	return kFskErrNone;
#endif /* TARGET_OS_IPHONE */

	// add loop back I/F to total number of IP addresses
	err = FskMemPtrNewClear(sizeof(FskNetInterfaceRecord), (FskMemPtr*)(void*)&nir);
	if (kFskErrNone == err) {
		nir->name = FskStrDoCopy("localhost");
		nir->ip = FskNetMakeIP(127,0,0,1);
		nir->netmask = 0xff000000;
		nir->status = 1;
		FskListAppend((FskList*)interfaceList, nir);
	}

bail:
	if (fd >= 0)		// coverity 10587
		close (fd);
	return err;
}
예제 #30
0
// ---------------------------------------------------------------------
static FskErr sFskNetInterfaceEnumerate(FskNetInterfaceRecord **interfaceList)
{
	DWORD	bytes, result;
	FskNetInterfaceRecord *nir;
	IP_ADAPTER_INFO	*adapters = NULL, *pAdapter;
	FskErr err = kFskErrNone;

	*interfaceList = NULL;

	result = GetAdaptersInfo(NULL, &bytes);
	if (result == ERROR_NO_DATA)
		return kFskErrNetworkInterfaceError;
	if (( ERROR_SUCCESS != result ) && (ERROR_BUFFER_OVERFLOW != result))
		return kFskErrNetworkInterfaceError;
	FskMemPtrNew(bytes, (FskMemPtr*)&adapters);

	result = GetAdaptersInfo(adapters, &bytes);
	if ( ERROR_SUCCESS != result )
        BAIL(kFskErrNetworkInterfaceError);

	for (pAdapter = adapters ; NULL != pAdapter ; pAdapter = pAdapter->Next){
		const IP_ADDR_STRING* ip = &pAdapter->IpAddressList;
		// NOTE: there may be more than one IP per interface - this does not handle that case
		FskInstrumentedTypePrintfDebug(&gNetInterfaceNotifierTypeInstrumentation,"Network Adapter %s", ip->IpAddress.String);
		// check for ppp, 0.0.0.0, etc.
		if (pAdapter->Type == IF_TYPE_PPP)
				continue;
		if (FskStrCompare("0.0.0.0", ip->IpAddress.String) == 0)
				continue;

		FskMemPtrNewClear(sizeof(FskNetInterfaceRecord), (FskMemPtr*)&nir);
		if (nir) {
			UInt32 j;
			nir->name = FskStrDoCopy(pAdapter->AdapterName);
			if (6 == pAdapter->AddressLength) {
				for(j = 0; j < pAdapter->AddressLength; j++)
					nir->MAC[j] = pAdapter->Address[j];
			}
			FskNetStringToIPandPort(ip->IpAddress.String, &nir->ip, NULL);
			FskNetStringToIPandPort(ip->IpMask.String, &nir->netmask, NULL);
			nir->status = 1;
			FskListAppend((FskList *)interfaceList, nir);
		}
	}

	// add loop back I/F to total number of IP addresses
	FskMemPtrNewClear(sizeof(FskNetInterfaceRecord), (FskMemPtr*)&nir);
	if (nir) {
		int j;
		nir->name = FskStrDoCopy("localhost");
		for(j = 0; j < 6; j++)
			nir->MAC[j] = 0;
		nir->ip = FskNetMakeIP(127,0,0,1);
		nir->netmask = 0xff000000;
		nir->status = 1;
		FskListAppend((FskList *)interfaceList, nir);
	}

bail:
	FskMemPtrDispose(adapters);

	return err;
}