コード例 #1
0
ファイル: fileops.c プロジェクト: gphat/loggeragent
void list(xmlDocPtr doc, xmlNodePtr cur) {
	xmlChar *directory;
	struct dirent *ent;
	DIR *dir;
	char *str;
	int retval = 0;

	directory = xmlGetProp(cur, (xmlChar *) "directory");
	if(directory == NULL) {
		llog(LOG_ERR, "list: Must specify a directory.");
		return;
	}

	dir = opendir((const char *) directory);

	if(dir == NULL) {
		llog(LOG_ERR, "list: opendir() failed: %s", strerror(errno));
		xmlFree(directory);
		return;
	} else {
		while((ent = readdir(dir)) != NULL) {
			str = lprintf("%s\n", ent->d_name);
			add_output(str);
			free(str);
			ent = readdir(dir);
		}
	}
	retval = closedir(dir);
	if(retval < 0) {
		llog(LOG_ERR, "list: closedir() failed: %s", retval);
	}

	xmlFree(directory);
}
コード例 #2
0
ファイル: fileops.c プロジェクト: gphat/loggeragent
void createfile(xmlDocPtr doc, xmlNodePtr cur) {
	int retval;
	xmlChar *filename;
	xmlChar *mode;
	mode_t imode = 0644;

	llog(LOG_DEBUG, "---- handler createfile ----");

	filename = xmlGetProp(cur, (xmlChar *) "filename");
	if(filename == NULL) {
		llog(LOG_ERR, "Must specify a filename.");
		return;
	}
	mode = xmlGetProp(cur, (xmlChar *) "mode");
	if(mode != NULL) {
		imode = (mode_t) (strtol((const char *)mode, NULL, 8));
	}
	llog(LOG_DEBUG, "Mode is %o", imode);

	retval = open((const char *)filename, O_CREAT | O_EXCL, imode);
	if(retval == -1) {
		llog(LOG_ERR, "open() failed: %s", strerror(errno));
	} else {
		llog(LOG_DEBUG, "open() succeeded");
	}

	xmlFree(filename);
	xmlFree(mode);
}
コード例 #3
0
ファイル: fileops.c プロジェクト: gphat/loggeragent
void statfile(xmlDocPtr doc, xmlNodePtr cur) {
	xmlChar *filename;
	struct stat buf;
	int retval;
	char *statstr;

	filename = xmlGetProp(cur, (xmlChar *) "filename");
	if(filename == NULL) {
		llog(LOG_ERR, "statfile: Must specify a filename.");
		return;
	}

	retval = stat((const char *) filename, &buf);

	if(retval == -1) {
		llog(LOG_ERR, "statfile: stat() failed: %s", strerror(errno));
		xmlFree(filename);
		return;
	} else {
		statstr = lprintf("UID:%d,GID:%d,Size:%d,Mode:%o\n", buf.st_uid, buf.st_gid, buf.st_size, buf.st_mode);
		add_output(statstr);
		free(statstr);
	}

	xmlFree(filename);
}
コード例 #4
0
ファイル: fileops.c プロジェクト: gphat/loggeragent
void mksymlink(xmlDocPtr doc, xmlNodePtr cur) {
	int retval;
	xmlChar *oldpath;
	xmlChar *newpath;

	oldpath = xmlGetProp(cur, (xmlChar *) "oldpath");
	if(oldpath == NULL) {
		llog(LOG_ERR, "mksymlink: Must specify an oldpath.");
		return;
	}
	newpath = xmlGetProp(cur, (xmlChar *) "newpath");
	if(newpath == NULL) {
		llog(LOG_ERR, "mksymlink: Must specify an newpath.");
		return;
	}

	retval = symlink((char *)oldpath, (char *)newpath);
	if(retval == -1) {
		llog(LOG_ERR, "mksymlink: symlink() failed: %s", strerror(errno));
	} else {
		llog(LOG_ERR, "mksymlink: symlink() succeeded");
	}
	xmlFree(oldpath);
	xmlFree(newpath);
}
コード例 #5
0
ファイル: fileops.c プロジェクト: gphat/loggeragent
void makedir(xmlDocPtr doc, xmlNodePtr cur) {
	int retval;
	xmlChar *dirname;
	xmlChar *mode;
	mode_t imode = 0644;

	dirname = xmlGetProp(cur, (xmlChar *) "dirname");
	if(dirname == NULL) {
		llog(LOG_ERR, "makedir: Must specify a dirname.");
		return;
	}

	mode = xmlGetProp(cur, (xmlChar *) "mode");
	if(mode != NULL) {
		imode = (mode_t) (strtol((const char *)mode, NULL, 8));
	}

	llog(LOG_DEBUG, "makedir: I am creating '%s' with mode %o", dirname, imode);
	retval = mkdir((char *)dirname, imode);
	if(retval == -1) {
		llog(LOG_ERR, "makedir: mkdir() failed: %s", strerror(errno));
	} else {
		llog(LOG_DEBUG, "makedir: mkdir() succeeded");
	}
	xmlFree(dirname);
	xmlFree(mode);
}
コード例 #6
0
ファイル: fileops.c プロジェクト: gphat/loggeragent
void move(xmlDocPtr doc, xmlNodePtr cur) {
	int retval;
	xmlChar *fromname;
	xmlChar *toname;

	fromname = xmlGetProp(cur, (xmlChar *) "fromname");
	if(fromname == NULL) {
		llog(LOG_ERR, "move: Must specify a fromname.");
		return;
	}
	toname = xmlGetProp(cur, (xmlChar *) "toname");
	if(toname == NULL) {
		llog(LOG_ERR, "move: Must specify a toname.");
		return;
	}
	llog(LOG_DEBUG, "move: I am moving '%s' to '%s'", fromname, toname);
	retval = rename((char *)fromname, (char *)toname);
	if(retval == -1) {
		llog(LOG_ERR, "move: rename() failed: %s", strerror(errno));
	} else {
		llog(LOG_DEBUG, "move: rename() succeeded");
	}
	xmlFree(fromname);
	xmlFree(toname);
}
コード例 #7
0
AgentTouch::AgentTouch() {
   // open sempahore
   semaphore = sem_open(AGENT_SEMAPHORE, O_RDWR);
   if (semaphore < 0)
      throw std::runtime_error("AgentTouch: sem_open() failed");

   // open shared memory as RW
   shared_fd = shm_open(AGENT_MEMORY, O_RDWR, 0600);
   if (shared_fd < 0)
      throw std::runtime_error("AgentTouch: shm_open() failed");

   // map shared memory to process memory
   shared_data = (AgentData*) mmap(NULL, sizeof(AgentData),
                                   PROT_READ | PROT_WRITE,
                                   MAP_SHARED, shared_fd, 0);
   if (shared_data == MAP_FAILED)
      throw std::runtime_error("AgentTouch: mmap() failed");

   if (pthread_mutex_trylock(&shared_data->lock)) {
      llog(QUIET) << "Another runswift is already running!" << std::endl;
      std::cerr << "Another runswift is already running!" << std::endl;
      exit(1);
   }

   llog(INFO) << "AgentTouch constructed" << std::endl;
}
コード例 #8
0
//********** Diagnostic Functions
void shaders_ListUniforms( GLuint shaderID )
{
	GLint count;
	GLint maxSize;
	GL( glGetProgramiv( shaderID, GL_ACTIVE_UNIFORMS, &count) );
	llog( LOG_INFO, "Uniforms for program %i:\n", shaderID );
	if( count == 0 ) {
		llog( LOG_INFO, "    none\n" );
	}

	GL( glGetProgramiv( shaderID, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxSize ) );
	char* uniformName = (char*)mem_Allocate( maxSize );
	if( uniformName == NULL ) {
		llog( LOG_WARN, "Error allocating memory for listing shader uniforms.\n" );
	}

	GLsizei length;
	GLint size;
	GLenum type;
	for( GLint i = 0; i < count; ++i ) {		
		GL( glGetActiveUniform( shaderID, i, maxSize, &length, &size, &type, uniformName ) );
		llog( LOG_INFO, "   %s\n", uniformName );
	}

	mem_Release( uniformName );
}
コード例 #9
0
ファイル: events.c プロジェクト: Dar13/lightship
/* ------------------------------------------------------------------------- */
char
event_unregister_listener(const struct game_t* game,
                          const char* event_directory,
                          event_callback_func callback)
{
    struct event_t* event;

    if(!(event = event_get(game, event_directory)))
    {
        llog(LOG_WARNING, game, NULL, 3, "Tried to unregister from event \"",
            event_directory, "\", but the event does not exist.");
        return 0;
    }

    { UNORDERED_VECTOR_FOR_EACH(&event->listeners, struct event_listener_t, listener)
    {
        if(listener->exec == callback)
        {
            unordered_vector_erase_element(&event->listeners, listener);
            return 1;
        }
    }}

    llog(LOG_WARNING, game, NULL, 3, "Tried to unregister from event \"",
        event_directory, "\", but the listener was not found.");

    return 0;
}
コード例 #10
0
ファイル: module.c プロジェクト: gphat/loggeragent
void unload_modules() {
	struct handler *h;
	int i, ret;
	struct module *m;
	void(*dfunc)();
	
	if(handlers != NULL) {
		for(i = 0; (h = handlers[i]) != NULL; i++) {
			free(h->name);
			free(h);
		}
		free(handlers);
	}

	if(dllist != NULL) {
		for(i = 0; (m = dllist[i]) != NULL; i++) {
			if(dfunc = m->destroyfunc) {
				llog(LOG_DEBUG, "Calling destroy function for module '%s'.", m->name);
				(*dfunc)();
			}
			llog(LOG_DEBUG, "Unloading module '%s', version %s.", m->name, m->version);
			free(m->name);
			free(m->version);
			ret = dlclose((void *) m->dl);
			if(ret != 0) {
				llog(LOG_ERR, "Error closing dl handle.");
			}
			free(m);
			llog(LOG_DEBUG, "Unload successfull.");
		}
		free(dllist);
	}
}
コード例 #11
0
/*
 * addValue: adds the value
 *	input: 	flow - some arbitrary flow
 *			value - the value to add and decrement
 *			max - some value to compare the new table value to, give a non positive if no comparison should take place
 *			timeout - the time in ms for the decrement to occur
 *	output: the given value or -1 if the max was surpassed with the new value added and not already surpassed
 */
int Async_Auto_Flow_Table::addValue(Flow flow, int value, int max, uint32_t timeout) {
	int ret = value;
	table_mutex.lock();

	table[flow] += value;

	llog(logDEBUG2) << "adding " << value << " to " << flow << " to make " << table[flow];

	if (table[flow] > max) {
		llog(logDEBUG) << "------------------------------------------------------------";
		llog(logDEBUG) << "FOUND higher value - " << flow;
		llog(logDEBUG) << "------------------------------------------------------------";
	}

	if ((max > 0) && (table[flow] > max) ) {
		if (recent.count(flow) == 0) {
			 recent[flow] = false;
		}
		if(!recent[flow]){
			ret = -1;
			recent[flow] = true;
		}
	}
	table_mutex.unlock();

	boost::shared_ptr<boost::asio::deadline_timer> timer(new boost::asio::deadline_timer(table_io, boost::posix_time::milliseconds(timeout)));
	timer->async_wait(boost::bind(&Async_Auto_Flow_Table::decrement, this, boost::asio::placeholders::error, timer, flow, value));
	return ret;
}
コード例 #12
0
ファイル: sound.c プロジェクト: JesseRahikainen/Xturos
static void bindSampleJob( void* data )
{
	if( data == NULL ) {
		llog( LOG_ERROR, "NULL data passed into loadSampleJob!" );
		return;
	}

	ThreadedSoundLoadData* loadData = (ThreadedSoundLoadData*)data;

	int newIdx = -1;
	for( int i = 0; ( i < ARRAY_SIZE( samples ) ) && ( newIdx < 0 ); ++i ) {
		if( samples[i].data == NULL ) {
			newIdx = i;
		}
	}

	if( newIdx < 0 ) {
		llog( LOG_ERROR, "Unable to find free space for sample." );
		goto clean_up;
	}

	// store it
	samples[newIdx].data = mem_Allocate( loadData->loadConverter.len_cvt );

	memcpy( samples[newIdx].data, loadData->loadConverter.buf, loadData->loadConverter.len_cvt );

	samples[newIdx].numChannels = loadData->desiredChannels;
	samples[newIdx].numSamples = loadData->loadConverter.len_cvt / ( loadData->desiredChannels * ( ( SDL_AUDIO_MASK_BITSIZE & WORKING_FORMAT ) / 8 ) );
	samples[newIdx].loops = loadData->loops;

	(*(loadData->outID)) = newIdx;

clean_up:
	cleanUpThreadedSoundLoadData( loadData );
}
コード例 #13
0
ファイル: images.c プロジェクト: JesseRahikainen/Xturos
/*
Loads the image stored at file name.
 Returns the index of the image on success.
 Returns -1 on failure, and prints a message to the log.
*/
int img_Load( const char* fileName, ShaderType shaderType )
{
	int newIdx = -1;

	// find the first empty spot, make sure we won't go over our maximum
	newIdx = findAvailableImageIndex( );
	if( newIdx < 0 ) {
		llog( LOG_INFO, "Unable to load image %s! Image storage full.", fileName );
		return -1;
	}

	Texture texture;
	if( gfxUtil_LoadTexture( fileName, &texture ) < 0 ) {
		llog( LOG_INFO, "Unable to load image %s!", fileName );
		newIdx = -1;
		return -1;
	}

	images[newIdx].textureObj = texture.textureID;
	images[newIdx].size.v[0] = (float)texture.width;
	images[newIdx].size.v[1] = (float)texture.height;
	images[newIdx].offset = VEC2_ZERO;
	images[newIdx].packageID = -1;
	images[newIdx].flags = IMGFLAG_IN_USE;
	images[newIdx].nextInPackage = -1;
	images[newIdx].uvMin = VEC2_ZERO;
	images[newIdx].uvMax = VEC2_ONE;
	images[newIdx].shaderType = shaderType;
	if( texture.flags & TF_IS_TRANSPARENT ) {
		images[newIdx].flags |= IMGFLAG_HAS_TRANSPARENCY;
	}

	return newIdx;
}
コード例 #14
0
ファイル: images.c プロジェクト: JesseRahikainen/Xturos
/*
Creates an image from a surface.
*/
int img_Create( SDL_Surface* surface, ShaderType shaderType )
{
	int newIdx;

	assert( surface != NULL );

	newIdx = findAvailableImageIndex( );
	if( newIdx < 0 ) {
		llog( LOG_INFO, "Unable to create image from surface! Image storage full." );
		return -1;
	}

	Texture texture;
	if( gfxUtil_CreateTextureFromSurface( surface, &texture ) < 0 ) {
		llog( LOG_INFO, "Unable to convert surface to texture! SDL Error: %s", SDL_GetError( ) );
		return -1;
	} else {
		images[newIdx].size.v[0] = (float)texture.width;
		images[newIdx].size.v[1] = (float)texture.height;
		images[newIdx].offset = VEC2_ZERO;
		images[newIdx].packageID = -1;
		images[newIdx].flags = IMGFLAG_IN_USE;
		images[newIdx].nextInPackage = -1;
		images[newIdx].uvMin = VEC2_ZERO;
		images[newIdx].uvMax = VEC2_ONE;
		images[newIdx].shaderType = shaderType;
		if( texture.flags & TF_IS_TRANSPARENT ) {
			images[newIdx].flags |= IMGFLAG_HAS_TRANSPARENCY;
		}
	}

	return newIdx;
}
コード例 #15
0
ファイル: module.c プロジェクト: gphat/loggeragent
void load_modules() {
	DIR	*plugins = NULL;
	struct dirent *ent;
	char *needle = NULL;
	char *sofile = NULL;
	char *plugindir = PLUGIN_DIR;

	plugins = opendir(plugindir);
	if(plugins == NULL) {
		llog(LOG_ERR, "opendir() failed: %s", strerror(errno));
		return;
	}

	llog(LOG_DEBUG, "Reading plugin directory, %s.", plugindir);
	while((ent = readdir(plugins)) != NULL) {
		needle = strstr(ent->d_name, ".so");
		if((needle != NULL) && (strlen(needle) == 3)) {
			llog(LOG_DEBUG, "Found file '%s'.", ent->d_name);
			sofile = (char *) lprintf("%s/%s", plugindir, ent->d_name);
			if(sofile == NULL) {
				llog(LOG_ERR, "lprintf() for sofile failed.");
				closedir(plugins);
				return;
			}
			llog(LOG_DEBUG, "Sending '%s' to load_module().", sofile);
			load_module(sofile);
			free(sofile);
		}
	}

	closedir(plugins);
}
コード例 #16
0
static void
my_connect_callback(struct mosquitto *mosq, void *userdata, int result)
{
	if (!result)
		llog(LOG_INFO, "MQTT: connection established.\n");
	else
		llog(LOG_ERR, "MQTT: connection failed.\n");
}
コード例 #17
0
ファイル: module.c プロジェクト: gphat/loggeragent
void module_stats() {
	int i = 0;
	struct handler *h;

	llog(LOG_INFO, "---- I have %d loaded handlers ----", handler_count);
	for(i = 0; (h = handlers[i]) != NULL; i++) {
		llog(LOG_INFO, "%s", h->name);
	}
}
コード例 #18
0
ファイル: images.c プロジェクト: JesseRahikainen/Xturos
/*
initializes the structure so only what's used needs to be set, also fill in
  some stuff that all of the queueRenderImage functions use, returns the pointer
  for further setting of other stuff
 returns NULL if there's a problem
*/
static DrawInstruction* GetNextRenderInstruction( int imgObj, uint32_t camFlags, Vector2 startPos, Vector2 endPos, int8_t depth )
{
	// the image hasn't been loaded yet, so don't render anything
	if( imgObj < 0 ) {
		// TODO: Use a temporary image.
		return NULL;
	}

	if( !( images[imgObj].flags & IMGFLAG_IN_USE ) ) {
		llog( LOG_VERBOSE, "Attempting to draw invalid image: %i", imgObj );
		return NULL;
	}

	if( lastDrawInstruction >= MAX_RENDER_INSTRUCTIONS ) {
		llog( LOG_VERBOSE, "Render instruction queue full." );
		return NULL;
	}

	++lastDrawInstruction;
	DrawInstruction* ri = &( renderBuffer[lastDrawInstruction] );

	*ri = DEFAULT_DRAW_INSTRUCTION;
	ri->textureObj = images[imgObj].textureObj;
	ri->imageObj = imgObj;
	ri->start.pos = startPos;
	ri->end.pos = endPos;
	ri->start.scaleSize = images[imgObj].size;
	ri->end.scaleSize = images[imgObj].size;
	ri->start.color = CLR_WHITE;
	ri->end.color = CLR_WHITE;
	ri->start.rotation = 0.0f;
	ri->end.rotation = 0.0f;
	ri->offset = images[imgObj].offset;
	ri->flags = images[imgObj].flags;
	ri->camFlags = camFlags;
	ri->shaderType = images[imgObj].shaderType;
	ri->depth = depth;
	ri->scissorID = scissor_GetTopID( );
	memcpy( ri->uvs, DEFAULT_DRAW_INSTRUCTION.uvs, sizeof( ri->uvs ) );

	ri->uvs[0] = images[imgObj].uvMin;

	ri->uvs[1].x = images[imgObj].uvMin.x;
	ri->uvs[1].y = images[imgObj].uvMax.y;

	ri->uvs[2].x = images[imgObj].uvMax.x;
	ri->uvs[2].y = images[imgObj].uvMin.y;

	ri->uvs[3] = images[imgObj].uvMax;

	return ri;
}
コード例 #19
0
void
client_unsubscribed(Subscriptions *subscriptions, Subscription *sub,
		    void *subscriber)
{
	llog(LOG_INFO, "Unsubscribe client %p from topic %s\n", subscriber,
	     sub->topic);

	if (sub->count_subscribed == 0)
	{
		llog(LOG_INFO, "No more subscribers left for topic %s. "
		     "Unsubscribe from server.\n", sub->topic);
		mosquitto_unsubscribe(MOSQUITTO, NULL, sub->topic);
	}
}
コード例 #20
0
ファイル: images.c プロジェクト: JesseRahikainen/Xturos
static void bindImageJob( void* data )
{
	if( data == NULL ) {
		llog( LOG_INFO, "No data, unable to bind." );
		return;
	}

	ThreadedLoadImageData* loadData = (ThreadedLoadImageData*)data;

	(*(loadData->outIdx)) = -1;

	if( loadData->loadedImage.data == NULL ) {
		llog( LOG_INFO, "Failed to load image %s", loadData->fileName );
		goto clean_up;
	}

	// find the first empty spot, make sure we won't go over our maximum
	int newIdx = findAvailableImageIndex( );
	if( newIdx < 0 ) {
		llog( LOG_INFO, "Unable to bind image %s! Image storage full.", loadData->fileName );
		goto clean_up;
	}

	Texture texture;
	if( gfxUtil_CreateTextureFromLoadedImage( GL_RGBA, &( loadData->loadedImage ), &texture ) < 0 ) {
		llog( LOG_INFO, "Unable to bind image %s!", loadData->fileName );
		goto clean_up;
	}

	images[newIdx].textureObj = texture.textureID;
	images[newIdx].size.v[0] = (float)texture.width;
	images[newIdx].size.v[1] = (float)texture.height;
	images[newIdx].offset = VEC2_ZERO;
	images[newIdx].packageID = -1;
	images[newIdx].flags = IMGFLAG_IN_USE;
	images[newIdx].nextInPackage = -1;
	images[newIdx].uvMin = VEC2_ZERO;
	images[newIdx].uvMax = VEC2_ONE;
	images[newIdx].shaderType = loadData->shaderType;
	if( texture.flags & TF_IS_TRANSPARENT ) {
		images[newIdx].flags |= IMGFLAG_HAS_TRANSPARENCY;
	}
	(*(loadData->outIdx)) = newIdx;

	llog( LOG_INFO, "Setting outIdx to %i", newIdx );

clean_up:
	gfxUtil_ReleaseLoadedImage( &( loadData->loadedImage ) );
	mem_Release( loadData );
}
コード例 #21
0
ファイル: systems.c プロジェクト: JesseRahikainen/Xturos
void sys_UnRegister( int systemID )
{
	if( ( systemID < 0 ) || ( systemID > MAX_SYSTEMS ) ) {
		llog( LOG_DEBUG, "Attempting to unregister an invalid system" );
		return;
	}

	if( !systemInUse( systemID ) ) {
		llog( LOG_DEBUG, "Attempting to unregister a system that has not been registered" );
		return;
	}

	systems[systemID] = emptySystem;
}
コード例 #22
0
ファイル: thread_pool_osx.c プロジェクト: Dar13/lightship
static void*
thread_pool_worker(struct thread_pool_t* pool)
{
    char thread_self_str[sizeof(int)*8+3];
    sprintf(thread_self_str, "0x%lx", (intptr_t)pthread_self());
    llog(LOG_INFO, NULL, 3, "Worker thread ", thread_self_str, " started");
    
    pthread_mutex_lock(&pool->mutex);
    thread_pool_process_while_active(pool);
    pthread_mutex_unlock(&pool->mutex);
    
    llog(LOG_INFO, NULL, 3, "Worker thread ", thread_self_str, " stopping");
    pthread_exit(NULL);
}
コード例 #23
0
static void
my_message_callback(struct mosquitto *mosq, void *userdata,
		    const struct mosquitto_message *message)
{
	if (message->payloadlen)
	{
		llog(LOG_INFO, "Received message %s : %s\n", message->topic,
		     message->payload);
		Subscription *subscription = subscription_get(&SUBSCRIPTIONS,
							      message->topic);
		if (subscription)
		{
			llog(LOG_INFO, "Notify %d lws clients for topic %s\n",
			     subscription->count_subscribed, message->topic);

			Message msg;
			message_new(&msg, PUBLISH, message->topic, message->payload);
			message_serialize_response(&msg);

			// create libwebsockets message from MQTT payload
			unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + msg.size
					  + LWS_SEND_BUFFER_POST_PADDING];
			unsigned char *lws_message = &buf[LWS_SEND_BUFFER_PRE_PADDING];
			int lws_message_length = sprintf((char* )lws_message, "%s",
							 msg.serialized);

			// dispatch message to all subscribers
			for (int i = 0; i < subscription->count_subscribed; i++)
			{
				struct libwebsocket *wsi = subscription->subscribers[i];
				int bytes_written = libwebsocket_write(wsi, lws_message,
								       lws_message_length, LWS_WRITE_TEXT);
				if (bytes_written < lws_message_length)
				{
					llog(LOG_ERR,
					     "ERROR only %d bytes written (message length is %d)\n",
					     bytes_written, lws_message_length);
				}
			}
			message_free(&msg);
		}
		else
			llog(LOG_ERR, "No lws clients are subscribed to topic %s\n",
			     message->topic);
	}
	else
		printf("%s (null)\n", message->topic);
}
コード例 #24
0
ファイル: sound.c プロジェクト: JesseRahikainen/Xturos
static void loadSampleJob( void* data )
{
	if( data == NULL ) {
		llog( LOG_ERROR, "NULL data passed into loadSampleJob!" );
		return;
	}

	ThreadedSoundLoadData* loadData = (ThreadedSoundLoadData*)data;

	// read the entire file into memory and decode it
	int channels;
	int rate;
	short* buffer;
	int numSamples = stb_vorbis_decode_filename( loadData->fileName, &channels, &rate, &buffer );

	if( numSamples < 0 ) {
		llog( LOG_ERROR, "Error decoding sound sample %s", loadData->fileName );
		goto error;
	}

	// convert it
	if( SDL_BuildAudioCVT( &( loadData->loadConverter ),
		AUDIO_S16, (Uint8)channels, rate,
		WORKING_FORMAT, loadData->desiredChannels, WORKING_RATE ) < 0 ) {
		llog( LOG_ERROR, "Unable to create converter for sound." );
		goto error;
	}

	loadData->loadConverter.len = numSamples * channels * sizeof( buffer[0] );
	size_t totLen = loadData->loadConverter.len * loadData->loadConverter.len_mult;
	if( loadData->loadConverter.len_mult > 1 ) {
		buffer = mem_Resize( buffer, loadData->loadConverter.len * loadData->loadConverter.len_mult ); // need to make sure there's enough room
		if( buffer == NULL ) {
			llog( LOG_ERROR, "Unable to allocate more memory for converting." );
			goto error;
		}
	}
	loadData->loadConverter.buf = (Uint8*)buffer;

	SDL_ConvertAudio( &( loadData->loadConverter ) );

	jq_AddMainThreadJob( bindSampleJob, (void*)loadData );

	return;

error:
	cleanUpThreadedSoundLoadData( loadData );
}
コード例 #25
0
SensorValues FilteredTouch::getSensors() {
   SensorValues update = touch->getSensors();
   struct timeval tv;
   static bool said = false;
   gettimeofday(&tv, NULL);
   if (tv.tv_sec % 5 == 0 && !said) {
      if (update.sonar[0] < Sonar::MIN)
         SAY("sonar error");
   }
   said = (tv.tv_sec % 5 == 0);
   if (init) {
      init = false;
      state = update;
      for (uint8_t i = 0; i < Sonar::NUMBER_OF_READINGS; ++i) {
         if (state.sonar[i] >= Sonar::INVALID || state.sonar[i] < Sonar::MIN)
            state.sonar[i] = 10.0f;
      }

   } else {
      state.joints = update.joints;
      uint8_t i;
      for (i = 0; i < Sensors::NUMBER_OF_SENSORS; ++i)
         state.sensors[i] = update.sensors[i];
      for (i = 0; i < Sonar::NUMBER_OF_READINGS; ++i) {
         if (update.sonar[i] >= Sonar::INVALID)
            update.sonar[i] = 10.0f;
         if (update.sonar[i] >= Sonar::MIN)
            state.sonar[i] += (update.sonar[i] - state.sonar[i]) * 1.0;
      }
      llog(VERBOSE) << state.sonar[0] << " " << state.sonar[10]  << std::endl;
   }
   return state;
}
コード例 #26
0
ファイル: images.c プロジェクト: JesseRahikainen/Xturos
/*
Splits the texture. Returns a negative number if there's a problem.
*/
int split( Texture* texture, int packageID, ShaderType shaderType, int count, Vector2* mins, Vector2* maxes, int* retIDs )
{
	Vector2 inverseSize;
	inverseSize.x = 1.0f / (float)texture->width;
	inverseSize.y = 1.0f / (float)texture->height;

	for( int i = 0; i < count; ++i ) {
		int newIdx = findAvailableImageIndex( );
		if( newIdx < 0 ) {
			llog( LOG_ERROR, "Problem finding available image to split into." );
			img_CleanPackage( packageID );
			return -1;
		}

		images[newIdx].textureObj = texture->textureID;
		vec2_Subtract( &( maxes[i] ), &( mins[i] ), &( images[newIdx].size ) );
		images[newIdx].offset = VEC2_ZERO;
		images[newIdx].packageID = packageID;
		images[newIdx].flags = IMGFLAG_IN_USE;
		vec2_HadamardProd( &( mins[i] ), &inverseSize, &( images[newIdx].uvMin ) );
		vec2_HadamardProd( &( maxes[i] ), &inverseSize, &( images[newIdx].uvMax ) );
		images[newIdx].shaderType = shaderType;
		if( texture->flags & TF_IS_TRANSPARENT ) {
			images[newIdx].flags |= IMGFLAG_HAS_TRANSPARENCY;
		}

		retIDs[i] = newIdx;
	}

	return 0;
}
コード例 #27
0
ファイル: text_analiz.cpp プロジェクト: spellanser/graphx
char *proobraz(char* input)
{
input = registr(input);

input=  ficha(input);
for (int i=0;i<strlen(input);i++)
    {
       ssin(i,input);
       ccos(i,input);
       aasin(i,input);
       aacos(i,input);
       aatan(i,input);
       cceil(i,input);
       cch(i,input);
       eexp(i,input);
       aabs(i,input);
       ffloor(i,input);
       lln(i,input);
       llog(i,input);
       ssh(i,input);
       ssqrt(i,input);
       ttan(i,input);
       tth(i,input);
       cctg(i,input);
	aactg(i,input);
	ccth(i,input);
    }
    return input;
}
コード例 #28
0
ファイル: sound.c プロジェクト: JesseRahikainen/Xturos
void snd_PlayStreaming( int streamID, float volume, float pan ) // todo: fade in?
{
	assert( ( streamID >= 0 ) && ( streamID < MAX_STREAMING_SOUNDS ) );
	SDL_LockAudioDevice( devID ); {
		if( ( streamingSounds[streamID].access != NULL ) && !streamingSounds[streamID].playing ) {

			streamingSounds[streamID].sdlStream = SDL_NewAudioStream( AUDIO_S16,
				(Uint8)( streamingSounds[streamID].access->channels ), streamingSounds[streamID].access->sample_rate,
				WORKING_FORMAT, streamingSounds[streamID].channels, WORKING_RATE );

			if( streamingSounds[streamID].sdlStream == NULL ) {
				llog( LOG_ERROR, "Unable to create SDL_AudioStream for streaming sound." );
				return;
			}

			streamingSounds[streamID].playing = true;
			streamingSounds[streamID].volume = volume;
			streamingSounds[streamID].pan = pan;

			stb_vorbis_seek_start( streamingSounds[streamID].access );

			streamingSounds[streamID].readDone = false;
		}
	} SDL_UnlockAudioDevice( devID );
}
コード例 #29
0
void getSystemMountPoint(char * dev) {
  FILE *f = fopen("/proc/mounts", "r");
  if (f == NULL) {
    printf("unable to read /proc/mounts: \n");
    exit(1);
  }

  char mountPoint[1024];
  char type[1024];
  char opts[1024];
  int freq;
  int passno;

  while(1) {
    int retval = fscanf(f, "%s %s %s %s %d %d", dev,
                        mountPoint, type, opts, &freq, &passno);
    if (retval != 6) {
      llog("getsysmntpnt wrong num args", retval);
      exit(1);
    }
    if (strcmp(mountPoint, "/system")) {
      return;
    }
  }
}
コード例 #30
0
AgentTouch::~AgentTouch() {
   pthread_mutex_unlock(&shared_data->lock);
   if (shared_data != MAP_FAILED) munmap(shared_data, sizeof(AgentData));
   if (shared_fd >= 0) close(shared_fd);
   if (semaphore != SEM_FAILED) sem_close(semaphore);
   llog(INFO) << "AgentTouch destroyed" << std::endl;
}