Exemplo n.º 1
0
    // t7 like platform - TODO
void scanVolumes() {
	int err;
	volInfo	vi, walker;
	struct statfs fsinfo;

// ROOT
	FskMemPtrNewClear(sizeof(volInfoRec), &vi);
	vi->type = kKplVolumeTypeFixed;
	vi->removable = false;
	vi->mounted = true;
	vi->typeStr = FskStrDoCopy("ext4");

	vi->mountPoint = FskStrDoCopy("/\0");
	vi->name = FskStrDoCopy("/\0");
	err = statfs("/", &fsinfo);
	vi->capacity = fsinfo.f_blocks * fsinfo.f_bsize;
	vi->remaining = fsinfo.f_bavail * fsinfo.f_bsize;
	vi->fsid = fsinfo.f_fsid;
	FskListAppend(&volumeList, vi);
//fprintf(stderr, " fsid: %d:%d, capacity: %d, remaining: %d\n", vi->fsid.__val[0], vi->fsid.__val[1], vi->capacity, vi->remaining);

// SDCARD - there may be a better way to do this
	FskMemPtrNewClear(sizeof(volInfoRec), &vi);
	vi->type = kKplVolumeTypeSDMemory;
	vi->removable = true;
	vi->mounted = true;
	vi->typeStr = FskStrDoCopy("vfat");

	vi->mountPoint = FskStrDoCopy("/mnt/external_sdcard/\0");
	vi->name = FskStrDoCopy("sdcard\0");
	vi->fsid.__val[0] = -1;
	vi->fsid.__val[1] = -1;
	err = statfs("/mnt/sdcard", &fsinfo);
	if (0 == err) {
		walker = volumeList;
		while (walker) {
			if ((fsinfo.f_fsid.__val[0] == walker->fsid.__val[0])
				&& (fsinfo.f_fsid.__val[1] == walker->fsid.__val[1])) {
				// same fsid - it's not a different mount
				break;
			}
			walker = walker->next;
		}
		if (!walker) {		// didn't find an entry with the same fsid
			vi->mounted = true;
			vi->fsid = fsinfo.f_fsid;
			vi->capacity = fsinfo.f_blocks * fsinfo.f_bsize;
			vi->remaining = fsinfo.f_bavail * fsinfo.f_bsize;
//fprintf(stderr, " fsid: %d:%d, capacity: %d, remaining: %d\n", vi->fsid.__val[0], vi->fsid.__val[1], vi->capacity, vi->remaining);
		}
	}
	if (vi->fsid.__val[0] == -1 && vi->fsid.__val[1] == -1) {
		FskMemPtrDispose(vi);
	}
	else
		FskListAppend(&volumeList, vi);
}
Exemplo n.º 2
0
void KprZeroconfServiceDiscover(KprService self, char* authority, char* id, Boolean useEnvironment)
{
	FskErr err = kFskErrNone;
	char* type = NULL;
	KprZeroconfBrowser browser = NULL;
	if (useEnvironment ? KprEnvironmentGetUInt32("useZeroconf", 0) : true) {
		bailIfError(KprZeroconfServiceNewType(id, &type));
		browser = KprZeroconfBrowserFind(gKprZeroconfBrowsers, type);
		if (!browser) {
			bailIfError(KprZeroconfBrowserNew(&browser, type));
			browser->serviceUpCallback = KprZeroconfServiceServiceUpCallback;
			browser->serviceDownCallback = KprZeroconfServiceServiceDownCallback;
			browser->authority = FskStrDoCopy(authority);
			bailIfError(KprZeroconfBrowserStart(browser));
			FskListAppend(&gKprZeroconfBrowsers, browser);
		}
	}
bail:
	if (err)
		KprZeroconfBrowserDispose(browser);
	FskMemPtrDispose(type);
	FskMemPtrDispose(authority);
	FskMemPtrDispose(id);
	return;
}
Exemplo n.º 3
0
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);
	}
}
Exemplo n.º 4
0
void xs_gpio_repeat(xsMachine* the)
{
    FskGPIO gpio = xsGetHostData(xsThis);

    if (gpio) {
        if (in != gpio->direction)
            xsThrowDiagnosticIfFskErr(kFskErrUnimplemented, "Digital pin %d cannot repeat on output pin", (int)gpio->pinNum);

        if (gpio->poller)
            FskListRemove(&gGPIOPollers, gpio);
        
        gpio->poller = (xsTest(xsArg(0))) ? xsGetHostData(xsArg(0)) : NULL;

        if (gpio->poller) {
            FskListAppend(&gGPIOPollers, gpio);
            gpio->pollerValue = -1;     // won't match
            if (NULL == gGPIOPoller) {
                FskTimeCallbackNew(&gGPIOPoller);
                FskTimeCallbackScheduleNextRun(gGPIOPoller, gpioPoller, NULL);
            }
        }
        else if ((NULL == gGPIOPollers) && (NULL != gGPIOPoller)) {
            FskTimeCallbackDispose(gGPIOPoller);
            gGPIOPoller = NULL;
        }
    }
}
Exemplo n.º 5
0
FskErr KprMessageInvoke(KprMessage self, KprMessageCallbackProc callback, KprMessageDisposeProc dispose, void* target)
{
	KprService service = gServices;
	FskInstrumentedItemSendMessageDebug(self, kprInstrumentedMessageInvoke, self);
	if (self->waiting)
		return kFskErrOutOfSequence;
	while (service) {
		if ((*service->accept)(service, self)) {
			self->waiting = true;
			if (target) {
				self->request.callback = callback;
				self->request.dispose = dispose;
				self->request.target = target;
				self->usage++; // request
			}
			FskListAppend(&gShell->messages, self);
			self->usage++; // message queue
			if (!service->thread)
				service->thread = KprShellGetThread(gShell);
			if (service == &gXKPRService)
				self->usage++; // event queue
			FskThreadPostCallback(service->thread, (FskThreadCallback)service->invoke, service, self, NULL, NULL);
			return kFskErrNone;
		}
		service = service->next;
	}
	return kFskErrUnimplemented;
}
Exemplo n.º 6
0
FskErr FskMuxerTrackNew(FskMuxer muxer, FskMuxerTrack *muxerTrackOut, const char *trackType, UInt32 scale)
{
	FskErr err;
	FskMuxerTrack track = NULL;

	err = FskMemPtrNewClear(sizeof(FskMuxerTrackRecord) + FskStrLen(trackType) + 1, &track);
	BAIL_IF_ERR(err);

	track->trackType = (char *)(track + 1);
	FskStrCopy(track->trackType, trackType);
	track->scale = scale;
	track->muxer = muxer;

	err = (muxer->dispatch->doNewTrack)(muxer, muxer->state, track, &track->dispatch, &track->state);
	BAIL_IF_ERR(err);

	FskListAppend((FskList*)(void*)&muxer->tracks, track);

bail:
	if (kFskErrNone != err) {
		FskMuxerTrackDispose(track);
		track = NULL;
	}

	*muxerTrackOut = track;

	return err;
}
Exemplo n.º 7
0
static FskErr KprSocketListenerNew(KprSocket owner, int ip, int port, KprSocketListener *it)
{
	KprSocketListener self = NULL;
	FskErr err;
	FskSocket skt = NULL;

	bailIfError(KprMemPtrNewClear(sizeof(KprSocketListenerRecord), &self));

	bailIfError(FskNetSocketNewTCP(&skt, true, "KprSocketListener"));

	FskNetSocketReuseAddress(skt);
	FskNetSocketMakeNonblocking(skt);

	bailIfError(FskNetSocketBind(skt, ip, port));
	bailIfError(FskNetSocketGetLocalAddress(skt, NULL, &port));

	self->owner = owner;
	self->ip = ip;
	self->port = port;
	self->socket = skt;
	skt = NULL;

	FskListAppend(&owner->listeners, self);
	if (it) *it = self;

bail:
	FskNetSocketClose(skt);

	if (err) {
		KprSocketListenerDispose(self);
	}

	return err;
}
Exemplo n.º 8
0
static FskErr KprSocketNewFromFskSocket(FskSocket skt, KprSocketFlags flags, KprSocket *it)
{
	FskErr err = kFskErrNone;
	KprSocket self = NULL;
	UInt32 ipaddr;
	char ipaddrStr[22];

	bailIfError(FskMemPtrNewClear(sizeof(KprSocketRecord), &self));

	bailIfError(FskNetSocketGetLocalAddress(skt, &ipaddr, &self->port));
	FskNetIPandPortToString(ipaddr, 0, ipaddrStr);
	self->host = FskStrDoCopy(ipaddrStr);
	bailIfNULL(self->host);

	self->mode = kKprSocketModeTCP;
	self->proto = kKprSocketProtoTCP;
	self->secure = (Boolean)(flags & kKprSocketFlagsSecure);

	bailIfError(KprSocketOnConnect(skt, self));

	*it = self;

	FskListAppend(&gSockets, self);

bail:
	if (err) {
		KprSocketDispose(self);
	}

	return err;
}
Exemplo n.º 9
0
static void DNSSD_API KprZeroconfPlatformResolveCallBack(DNSServiceRef resolveRef, DNSServiceFlags flags, uint32_t interfaceIndex, DNSServiceErrorType errorCode, const char *fullname, const char *hostname, uint16_t port, uint16_t txtLen, const unsigned char *txtRecord, void *context)
{
	FskErr err = kFskErrNone;
	KprZeroconfBrowser self = context;
	KprZeroconfPlatformBrowser browser = self->platform;
	KprZeroconfPlatformService resolver = KprZeroconfPlatformServiceFind(browser->services, resolveRef);
	if (!resolver || (errorCode != kDNSServiceErr_NoError)) {
		FskInstrumentedItemPrintfDebug(browser, "KprZeroconfPlatformResolveCallBack returned %d\n", errorCode);
	}
	else {
		DNSServiceErrorType error;
		DNSServiceRef serviceRef;
		KprZeroconfPlatformService service = NULL;
		FskInstrumentedItemPrintfDebug(browser, "RESOLVE: %s %s is at %s:%d", self->serviceType, resolver->name, hostname, ntohs(port));
		error = DNSServiceGetAddrInfo(&serviceRef, 0, interfaceIndex, kDNSServiceProtocol_IPv4, hostname, KprZeroconfPlatformGetAddrInfoCallBack, self);
		if (error != kDNSServiceErr_NoError) {
			bailIfError(kFskErrNetworkErr);
		}
		bailIfError(KprZeroconfPlatformServiceNew(&service, resolver->owner, serviceRef, resolver->name, ntohs(port)));
		if (txtLen > 1) {
			bailIfError(FskMemPtrNewClear(txtLen, &service->txt));
			FskStrNCopy(service->txt, (const char*)txtRecord, txtLen);
		}
		FskListAppend(&browser->services, service);
		FskListRemove(&browser->services, resolver);
		KprZeroconfPlatformServiceDispose(resolver);
	}
bail:
    return;
}
Exemplo n.º 10
0
void FskGtkWindowSetMenuItemCallback(FskGtkWindow win, GtkWidget* menuItem, int id)
{
	FskEvent fskEvent;
	menuItems entry = NULL;

	if(kFskErrNone == FskMemPtrNewClear(sizeof(menuItemsRecord), (FskMemPtr*)&entry)) {
		menuBars entryBar = NULL;
		entry->win = win;
		entry->id  = id;
		entry->item= menuItem;
		
		entryBar = win->menu;
		while(entryBar) {
			if(entryBar->id == (id & 0xFF00)) {
				break;
			}
			entryBar = entryBar->next;
		}
		FskListAppend(&entryBar->menulist, entry);
		
		// Update menuItem immediately (enabled? checked?)
		if(kFskErrNone == FskEventNew(&fskEvent, kFskEventMenuStatus, NULL, kFskEventModifierNotSet)) {
			FskEventParameterAdd(fskEvent, kFskEventParameterCommand, sizeof(id), &id);
			FskWindowEventSend(win->owner, fskEvent);
		}
		g_signal_connect(menuItem, "activate", G_CALLBACK(menu_select_cb), (gpointer)entry);
	}
}
Exemplo n.º 11
0
FskErr KprDebugMachineNew(KprDebugMachine* it, KprDebug debug, FskSocket skt)
{
	FskErr err = kFskErrNone;
	KprDebugMachine self = NULL;
	UInt32 ip;
	int port;
	
	BAIL_IF_ERR(err = FskMemPtrNewClear(sizeof(KprDebugMachineRecord), it));
	self = *it;
	self->debug = debug;
	self->socket = skt;

	BAIL_IF_ERR(err = FskNetSocketGetRemoteAddress(skt, &ip, &port));
	FskNetIPandPortToString(ip, port, self->address);

	FskListAppend(&self->debug->machine, self);

	FskNetSocketReceiveBufferSetSize(self->socket, kSocketBufferSize);

	FskThreadAddDataHandler(&self->reader, (FskThreadDataSource)self->socket, KprDebugMachineDataReader, true, false, self);

	bailIfError(KprSocketWriterNew(&self->writer, self->socket, self));
	self->writer->errorCallback = KprDebugMachineWriteError;

	KprDebugMachineCallbackText(self, "onMachineRegistered", mxNoCommand, NULL);

	FskInstrumentedItemNew(self, NULL, &KprDebugMachineInstrumentation);
	return err;
bail:
	KprDebugMachineDispose(self);
	return err;
}
Exemplo n.º 12
0
FskErr KprCoAPClientStartRequest(KprCoAPClient self, UInt32 ipaddr, UInt16 port, KprCoAPMessage message)
{
	FskErr err = kFskErrNone;
	KprCoAPClientRequest request = NULL;
	KprCoAPEndpoint endpoint = NULL;
	KprMemoryBlock generatedToken = NULL;

	if (self->autoToken && message->token == NULL) {
		bailIfError(KprCoAPClientNextAutoToken(self, &generatedToken));
		message->token = KprRetain(generatedToken);
		KprMemoryBlockDispose(generatedToken);
	}

	bailIfError(KprCoAPClientGetEndpoint(self, ipaddr, port, &endpoint));

	bailIfError(KprCoAPClientRequestNew(&request, self, message, endpoint));
	FskListAppend(&self->requests, request);

	bailIfError(KprCoAPEndpointSendMessage(endpoint, message));

bail:
	if (err) {
		FskListRemove(&self->requests, request);
		KprCoAPClientRequestDispose(request);

		KprCoAPClientDisposeUnusedEndpoint(self);
	}
	return err;
}
Exemplo n.º 13
0
FskErr KprCoAPClientSendRequest(KprCoAPClient self, KprCoAPMessage message)
{
	FskErr err = kFskErrNone;
	const char *host = message->host;
	UInt16 port = message->port;
	KprCoAPClientResolver dest = self->resolvers;

	while (dest) {
		if (port == dest->port && FskStrCompareCaseInsensitive(host, dest->host) == 0) break;

		dest = dest->next;
	}

	if (dest) {
		if (KprCoAPClientResolverIsResolved(dest)) {
			err = KprCoAPClientStartRequest(self, dest->ipaddr, port, message);
		} else {
			err = KprCoAPClientResolverQueueMessage(dest, message);
		}
	} else {
		bailIfError(KprCoAPClientResolverNew(&dest, self, host, port, message));
		FskListAppend(&self->resolvers, dest);
	}

bail:
	return err;
}
Exemplo n.º 14
0
static FskErr sFskNetInterfaceEnumerate(FskNetInterfaceRecord **interfaceList)
{
	FskErr err;
	KplNetInterfaceRecord *kplInterfaceList;

	*interfaceList = NULL;

	err = KplNetInterfaceEnumerate(&kplInterfaceList);
	BAIL_IF_ERR(err);

	while (kplInterfaceList) {
		FskNetInterfaceRecord *nir;
		KplNetInterfaceRecord *next = kplInterfaceList->next;

		err = FskMemPtrNew(sizeof(FskNetInterfaceRecord), (FskMemPtr*)&nir);
		BAIL_IF_ERR(err);

		nir->name = FskStrDoCopy(kplInterfaceList->name);
		nir->ip = kplInterfaceList->ip;
		FskMemMove(nir->MAC, kplInterfaceList->MAC, sizeof(nir->MAC));
		nir->status = kplInterfaceList->status;
		nir->netmask = kplInterfaceList->netmask;

		FskListAppend((FskList*)interfaceList, nir);

		FskMemPtrDispose(kplInterfaceList->name);
		FskMemPtrDispose(kplInterfaceList);

		kplInterfaceList = next;
	}

bail:
	return err;
}
Exemplo n.º 15
0
FskErr KprZeroconfBrowserStart(KprZeroconfBrowser self)
{
	FskErr err = kFskErrNone;
	bailIfError(KprZeroconfPlatformBrowserStart(self));
	FskListAppend(&gZeroconfBrowsers, self);
bail:
	return err;
}
Exemplo n.º 16
0
FskErr KprSSDPClientStart(KprSSDPClient self)
{
	FskErr err = kFskErrNone;
	FskListAppend(&gKprSSDPClients, self);
	FskThreadPostCallback(KprHTTPGetThread(), (FskThreadCallback)KprSSDPDiscover, self->type, self->services, KprSSDPClientCallback, self);
//bail:
	return err;
}
Exemplo n.º 17
0
FskErr KprMQTTQueueInboxPut(KprMQTTQueue self, KprMQTTMessage *it)
{
	KprMQTTMessage message = *it;

	if (KprMQTTQueueInboxFind(self, message->messageId) != NULL) return kFskErrDuplicateElement;

	FskListAppend(&self->inbox, message);

	*it = NULL;
	return kFskErrNone;
}
Exemplo n.º 18
0
FskErr KprMQTTMessageAddSubscribeTopic(KprMQTTMessage message)
{
	KprMQTTSubscribeTopic topic;
	FskErr err;

	err = FskMemPtrNewClear(sizeof(KprMQTTSubscribeTopicRecord), &topic);
	if (err) return err;

	FskListAppend(&message->t.other.topics, topic);
	return kFskErrNone;
}
Exemplo n.º 19
0
FskErr KplNetInterfaceEnumerate(KplNetInterfaceRecord **interfaceList)
{
	FskErr err = kFskErrNone;
	KplNetInterfaceRecord *nir;
	struct ifaddrs* ifaddr = NULL;
	struct ifaddrs* ifa;
	int fd = -1;
	struct ifreq  ifr;
    
	*interfaceList = NULL;

	if (getifaddrs(&ifaddr) == -1) {
		err = kFskErrNetworkInterfaceError;
		goto done;
	}
	
	fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
	if (fd < 0) goto done;
    
	for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
		if (ifa->ifa_addr == NULL)
			continue;

		if (ifa->ifa_addr->sa_family == AF_INET) {
			memset(&ifr, 0,  sizeof(struct ifreq));
			strncpy(ifr.ifr_name, ifa->ifa_name, IFNAMSIZ);
			ifr.ifr_name[IFNAMSIZ - 1] = 0;
            
			FskMemPtrNewClear(sizeof(KplNetInterfaceRecord), (FskMemPtr *)&nir);
			if (!nir) {
				err = kFskErrMemFull;
				goto done;
			}
			nir->name = FskStrDoCopy(ifa->ifa_name);
			nir->ip = ntohl(((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr);
			nir->netmask = ntohl(((struct sockaddr_in *)ifa->ifa_netmask)->sin_addr.s_addr);
			nir->status = (ifa->ifa_flags & IFF_UP) ? 1 : 0;
			if (ioctl(fd, SIOCGIFHWADDR, &ifr) >= 0) {
				if (ifr.ifr_hwaddr.sa_family == ARPHRD_ETHER) {
					FskMemCopy(nir->MAC, ifr.ifr_hwaddr.sa_data, 6);
				}
			}
			FskListAppend((FskList*)interfaceList, nir);
		}
	}
    
done:
	if (fd >= 0)
		close(fd);
	if (ifaddr)
		freeifaddrs(ifaddr);
	return err;
}
Exemplo n.º 20
0
static FskErr httpServerListenerStart(FskHTTPServerListener listener, FskSocket skt) {
	FskErr err = kFskErrNone;
	FskHTTPServerRequest request;

	if (listener->http->stopped) {
		FskInstrumentedItemSendMessage(listener->http, kFskHTTPInstrMsgConnectionRefusedStopped, listener);
		listener->http->stats.connectionsRefused++;
		FskNetSocketClose(skt);
		goto bail;
	}
		
	err = FskMemPtrNewClear(sizeof(FskHTTPServerRequestRecord), (FskMemPtr*)&request);
	BAIL_IF_ERR(err);

	sFskHTTPServerRequestUpUse(request);

	request->http = listener->http;
	request->skt = skt;	
	FskNetSocketGetRemoteAddress(skt, (UInt32 *)&request->requesterAddress, &request->requesterPort);
	FskNetSocketMakeNonblocking(request->skt);
	err = FskHeaderStructNew(&request->requestHeaders);
	BAIL_IF_ERR(err);
	err = FskHeaderStructNew(&request->responseHeaders);
	BAIL_IF_ERR(err);
	request->in.bufferSize = request->http->defaultBufferSize;
	request->out.bufferSize = request->http->defaultBufferSize;
	err = FskMemPtrNew(request->in.bufferSize, (FskMemPtr*)&request->in.buf);
	BAIL_IF_ERR(err);
	err = FskMemPtrNew(request->out.bufferSize, (FskMemPtr*)&request->out.buf);
	BAIL_IF_ERR(err);

	FskListAppend((FskList*)&request->http->activeRequests, request);
	FskTimeCallbackNew(&request->cycleCallback);
	FskTimeCallbackNew(&request->keepAliveKillCallback);

	listener->http->stats.connectionsMade++;

	request->state = kHTTPNewSession;

	FskInstrumentedItemNew(request, NULL, &gFskHTTPServerRequestTypeInstrumentation);
	FskInstrumentedItemSetOwner(request, request->http);
	
	FskTimeCallbackScheduleNextRun(request->cycleCallback, httpServerTimeCycle, request);
	doCallCondition(request->http->callbacks->requestCondition, request, kFskHTTPConditionConnectionInitialized, request->refCon);
	FskTimeCallbackNew(&request->timer);
	FskTimeCallbackScheduleFuture(request->timer, 1, 0, KprHTTPServerTimerCallback, request);
bail:
	if (err)
		FskHTTPServerRequestDispose(request);
	return err;
}
Exemplo n.º 21
0
////////////// Menu processing /////////////////
void FskGtkWindowSetMenuBar(FskGtkWindow win, GtkWidget* menuBar, int id)
{
	menuBars entryBar = NULL;
	gtk_menu_shell_append(GTK_MENU_SHELL(win->menubar), menuBar);
	gtk_widget_show(menuBar);

	if(kFskErrNone == FskMemPtrNewClear(sizeof(menuBarsRecord), (FskMemPtr*)&entryBar)) {
		entryBar->item 	= menuBar;
		entryBar->id   	= id & 0xFF00;		// id for the whole group
		entryBar->menulist = NULL;

		FskListAppend(&win->menu, entryBar);
	}
}
Exemplo n.º 22
0
////////////// Menu processing /////////////////
void FskGtkWindowSetMenuBar(FskGtkWindow win, GtkWidget* menu, int id)
{
	menuBars entryBar = NULL;

	gtk_menu_shell_append(GTK_MENU_SHELL(win->menubar), menu);

	if(kFskErrNone == FskMemPtrNewClear(sizeof(menuBarsRecord), (FskMemPtr*)&entryBar)) {
		entryBar->win  = win;
		entryBar->item = menu;
		entryBar->id   = id & 0xFF00;		// id for the whole group
		entryBar->menulist = NULL;

		FskListAppend(&win->menu, entryBar);
		g_signal_connect(menu, "button-press-event", G_CALLBACK(on_menu_press_cb), entryBar);
	}
}
Exemplo n.º 23
0
static FskErr KprWebSocketServerAcceptNewConnection(KprSocketServer server, FskSocket skt, const char *interfaceName, void *refcon) {
	KprWebSocketServer self = refcon;
	FskErr err = kFskErrNone;
	KprWebSocketServerRequest request;

	if (self->stopped) {
		FskNetSocketClose(skt);
		goto bail;
	}

	bailIfError(KprWebSocketServerRequestNew(&request, self, skt));
	FskListAppend((FskList*)&self->activeRequests, request);

bail:
	return err;
}
Exemplo n.º 24
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;
}
Exemplo n.º 25
0
void on_drag_data_received(GtkWidget* widget, GdkDragContext* context, gint x, gint y, GtkSelectionData *data, guint info, guint time, gpointer user_data)
{
	FskGtkWindow gtkWin = user_data;
	gboolean dnd_success = FALSE;
	FskDragDropFile dropFileList = NULL;
	FskDragDropFile droppedFile = NULL;
	char* path = NULL;
	if (gdk_drag_context_get_suggested_action(context) == GDK_ACTION_COPY) {
		char* string = (char*)gtk_selection_data_get_data(data);
		char* end;
		FskFileInfo itemInfo;
		for (end = FskStrStr(string, "\r\n"); end; end = FskStrStr(string, "\r\n")) {
			BAIL_IF_ERR(FskMemPtrNewClear(sizeof(FskDragDropFileRecord), (FskMemPtr*)&droppedFile));
			FskListAppend((FskList *)&dropFileList, droppedFile);
			*end = 0;
			BAIL_IF_ERR(KprURLToPath(string, &path));
			BAIL_IF_ERR(FskFileGetFileInfo(path, &itemInfo));
			if (itemInfo.filetype == kFskDirectoryItemIsDirectory) {
				int length = FskStrLen(path);
				BAIL_IF_ERR(FskMemPtrNew(length + 2, &droppedFile->fullPathName));
				FskMemCopy(droppedFile->fullPathName, path, length);
				droppedFile->fullPathName[length] = '/';
				droppedFile->fullPathName[length + 1] = 0;
				FskMemPtrDispose(path);
			}
			else {
				droppedFile->fullPathName = path;
			}
			path = NULL;
			string = end + 2;
			*end = '\r';
		}
		(*gDropTargetProc)(kFskDragDropTargetEnterWindow, x, y, dropFileList, gtkWin->owner);
		(*gDropTargetProc)(kFskDragDropTargetDropInWindow, x, y, dropFileList, gtkWin->owner);
		dnd_success = TRUE;
	}
bail:
	gtk_drag_finish(context, dnd_success, TRUE, time);
	FskMemPtrDispose(path);
	while (NULL != dropFileList) {
		droppedFile = dropFileList;
		FskListRemove((FskList *)&dropFileList, droppedFile);
		FskMemPtrDispose(droppedFile->fullPathName);
		FskMemPtrDispose(droppedFile);
	}
}
Exemplo n.º 26
0
void scanVolumes() {
	FILE *mountList;
	struct mntent	*cur;
	int err;
	volInfo	vi;
	mntdevmap *walker;
	struct statfs fsinfo;

	mountList = setmntent(kKplLinuxVolumeListFile, "r");
	if (mountList) {
		while (NULL != (cur = getmntent(mountList))) {
			err = statfs(cur->mnt_dir, &fsinfo);
			if (0 != err) {
				continue;
			}

			for (walker = gMntDevMap; NULL != walker->name; walker++) {
				if (0 == FskStrCompareWithLength(cur->mnt_type, walker->name, FskStrLen(walker->name)))
					break;
			}

			if (!walker->name) {
				continue;
			}

			FskMemPtrNewClear(sizeof(volInfoRec), &vi);
			vi->type = walker->type;
			vi->removable = walker->removable;
			vi->mounted = true;
			vi->typeStr = FskStrDoCopy(cur->mnt_type);

			if (kFskErrNone == FskMemPtrNew(FskStrLen(cur->mnt_dir) + 2, &vi->mountPoint)) {
				FskStrCopy(vi->mountPoint, cur->mnt_dir);
				if (vi->mountPoint[FskStrLen(vi->mountPoint)-1] != '/')
					FskStrCat(vi->mountPoint, "/");
			}

			vi->name = copyNiceName(cur->mnt_fsname);
			vi->capacity = fsinfo.f_blocks * fsinfo.f_bsize;
			vi->remaining = fsinfo.f_bavail * fsinfo.f_bsize;
			FskListAppend(&volumeList, vi);
		}
		endmntent(mountList);
	}
}
Exemplo n.º 27
0
FskErr KprDebugNew(KprDebug* it, UInt32 port)
{
	FskErr err = kFskErrNone;
	KprDebug self = NULL;
	BAIL_IF_ERR(err = FskMemPtrNewClear(sizeof(KprDebugRecord), it));
	self = *it;
	self->port = port;
	BAIL_IF_ERR(err = KprSocketServerNew(&self->server, self));
	self->server->debugName = "Debug";
	self->server->acceptCallback = KprDebugAcceptNewConnection;
	BAIL_IF_ERR(err = KprSocketServerListen(self->server, self->port, NULL));
	FskListAppend(&gKprDebugList, self);
	FskInstrumentedItemNew(self, NULL, &KprDebugInstrumentation);
	return err;
bail:
	KprDebugDispose(self);
	return err;
}
Exemplo n.º 28
0
FskErr KprCoAPClientEndRequest(KprCoAPClient self, KprCoAPClientRequest request, const char *reason)
{
	FskErr err = kFskErrNone;

	if (self->callbacks.requestEndCallback) {
		bailIfError(self->callbacks.requestEndCallback(request->message, reason, self->refcon));
	}

	FskListRemove(&self->requests, request);

	if (request->message->token) {
		FskListAppend(&self->recycleTokens, KprRetain(request->message->token));
	}

	bailIfError(KprCoAPClientRequestDispose(request));

bail:
	return err;
}
Exemplo n.º 29
0
void addVolume(char *path, int type, int removable) {
	pMount 	mnt;
	char 	*tmp;
	FskErr	err;

	if ('/' == path[FskStrLen(path)-1])
		tmp = FskStrDoCopy(path);
	else
		tmp = FskStrDoCat(path, "/");

	if (NULL != volumesContain(tmp)) {
		FskMemPtrDispose(tmp);
		return;
	}

	err = FskMemPtrNewClear(sizeof(sMountRec), &mnt);
	BAIL_IF_ERR(err);
	mnt->mountPoint = tmp;

	if (sNumMounts == 0) {
		mnt->name = FskStrDoCopy(kInternalDataStorageName);
	}
	else {
		gNumCards++;
		if (gNumCards > 1) {
			char *name = FskStrDoCat("Card (", path);
			mnt->name = FskStrDoCat(name, ")");
			FskMemPtrDispose(name);
		}
		else {
			mnt->name = FskStrDoCopy("Card");
		}
	}
	mnt->type = type;
	mnt->removable = removable;
	mnt->fsID = ++sNumMounts;
	FskListAppend(&gMounts, mnt);

bail:
	;
}
Exemplo n.º 30
0
// Insert this timer callback into the owning thread's "timerCallbacks" queue.
void sInsertInTime(KplTimeCallback el)
{
	KplTimeCallback cur, last = NULL;
	Boolean reschedule = false;
	KplTimeRecord now;
	KplThread thread;

	thread = (KplThread)el->owner;

	KplTimeGetNow(&now);
	if (1 == FskTimeCompare((FskTime)&el->trigger, (FskTime)&now))
		el->trigger = now;
	cur = (KplTimeCallback)FskListGetNext(thread->timerCallbacks, NULL);
	el->next = NULL;
	el->marked = false;

	if (cur == NULL) {
		FskListPrepend(&thread->timerCallbacks, el);
		reschedule = true;
		goto done;
	}
	while (cur) {
		if (FskTimeCompare((FskTime)&el->trigger, (FskTime)&cur->trigger) > 0) {
			if (last == NULL) {
				reschedule = true;
			}
			FskListInsertAfter(&thread->timerCallbacks, el, last);
			goto done;
		}

		last = cur;
		cur = cur->next;
	}
	if (!cur && last) {
		FskListAppend(&thread->timerCallbacks, el);
	}
	
done:
	if (reschedule)
		rescheduleTimer(thread);
}