예제 #1
0
파일: mas.c 프로젝트: KpuBopy4ka/obexd-map
static int mas_init(void)
{
	int err;
	int i;

	err = messages_init();
	if (err < 0)
		return err;

	for (i = 0; map_drivers[i] != NULL; ++i) {
		err = obex_mime_type_driver_register(map_drivers[i]);
		if (err < 0)
			goto failed;
	}

	err = obex_service_driver_register(&mas);
	if (err < 0)
		goto failed;

	return 0;

failed:
	for (--i; i >= 0; --i)
		obex_mime_type_driver_unregister(map_drivers[i]);

	messages_exit();

	return err;
}
예제 #2
0
int
/*main( int argc, char **argv )
{*/
test_message(){

  char *comeback, one[] = "the quick brown fox", two[]="jumps over the lazy dog";
  pthread_t receive = pthread_self();
  int size;

  /* Don't start if we can't get the message system working. */

  if (messages_init() == MSG_OK) {

    /* Send and receive from destination process 1 (without threads running, we'll receive on thread 1 in torch's pthread implementation. */

    /* Send a single message for starters. */

    if (send_message_to_thread( receive, one, strlen(one)+1) != MSG_OK) {
      printf( "first failed\n" );
    }

    if (receive_message( &receive, &comeback, &size) == MSG_OK) {
      printf ("received message 1--%s--size %d\n", comeback, size );
    } else {
      printf ("first receive failed\n");
    }

    /* Ensure that we can have some capacity in our message system. */

    if (send_message_to_thread( receive, two, strlen(two)+1) != MSG_OK) {
      printf( "second 1 failed\n" );
    }
    if (send_message_to_thread( receive, one, strlen(one)+1) != MSG_OK) {
      printf( "second 2 failed\n" );
    }

    if (receive_message( &receive, &comeback, &size) == MSG_OK) {
      printf ("received message 2--%s--size %d\n", comeback, size );
    } else {
      printf ("second 1 receive failed\n");
    }

    if (receive_message( &receive, &comeback, &size) == MSG_OK) {
      printf ("received message 3--%s--size %d\n", comeback, size );
    } else {
      printf ("second 2 receive failed\n");
    }

    /* Clean up the message system. */

    messages_end();
  }

  return 1;
}
예제 #3
0
파일: lib_os.c 프로젝트: richese/aeris
void lib_os_init()
{
	kernel_init();

	#ifdef _MESSAGES_F_H
	messages_init();
	#endif

	#ifdef _STDIO_H_
	stdio_init();
	#endif
}
예제 #4
0
/***********************************
 *  Main
 ***********************************/
int main( int argc, char *argv[] )
{

    //Get mailbox ready
    messages_init();

    // Read in from command line for authFile name and serviceFile name
    if (argc != 3)
    {
        printf ("Incorrect number of parameters read in, exiting\n");
        return 1;
    }

    // Define a list for service file and read it in
    List_t *serviceFileList;
    serviceFileList = readInServiceFile(argv[2]);

    // Create auth struct
    authStruct *auth;

    // Allocate memory for auth struct
    auth = (authStruct *) malloc( sizeof( authStruct ) );

    // Add values to auth struct for filename and secret value of ticket thread
    strncpy( auth->fileName, argv[1], CHAR_MAX - 1 );
    auth->fileName[CHAR_MAX - 1] = '\0'; /* Make sure that it is null-terminated. */
    strncpy( auth->secretValue, ticketGrantingSecret, TICKET_SECRET_MAX - 1 );
    auth->secretValue[TICKET_SECRET_MAX] = '\0'; /* Make sure that it is null-terminated. */

    /* Create client thread, auth thread, service thread and ticket thread */
    // Create client thread
    if (pthread_create(&clientThreadRef, NULL, clientThread, NULL))
    {
        fprintf(stderr, "Error creating thread\n");
    }

    // Create auth thread
    if (pthread_create(&authThreadRef, NULL, authThread, auth))
    {
        fprintf(stderr, "Error creating thread\n");
    }

    // Create service thread
    if (pthread_create(&serviceThreadRef, NULL, serviceThread, NULL))
    {
        fprintf(stderr, "Error creating thread\n");
    }

    // Create ticket granting thread
    if (pthread_create(&ticketThreadRef, NULL, ticketGrantingThread, serviceFileList))
    {
        fprintf(stderr, "Error creating thread\n");
    }


    /* Wait for threads to finish */

    // Wait for service thread to end
    if (pthread_join(serviceThreadRef, NULL))
    {
        fprintf(stderr, "Error joining thread\n");
        return 2;
    }

    // Wait for ticket granting thread to end
    if (pthread_join(ticketThreadRef, NULL))
    {
        fprintf(stderr, "Error joining thread\n");
        return 2;
    }

    // Wait for client thread to end
    if (pthread_join(clientThreadRef, NULL))
    {
        fprintf(stderr, "Error joining thread\n");
        return 2;
    }

    // Wait for auth thread to end
    if (pthread_join(authThreadRef, NULL))
    {
        fprintf(stderr, "Error joining thread\n");
        return 2;
    }

    // End program
    return 1;
}
예제 #5
0
파일: wizard2.c 프로젝트: MarvinPA/mpa-sil
/*
 * Become unaware of objects, monster memory, and the map
 */
static void do_cmd_wiz_forget(void)
{
	int i;
	
	/* Forget info about objects on the map */
	for (i = 1; i < o_max; i++)
	{
		object_type *o_ptr = &o_list[i];
		object_kind *k_ptr = &k_info[o_ptr->k_idx];
	
		/* Skip non-objects */
		if (!o_ptr->k_idx) continue;
		
		// identify non-special non-artefact weapons/armour		
		switch (o_ptr->tval)
		{
			case TV_DIGGING:
			case TV_HAFTED:
			case TV_POLEARM:
			case TV_SWORD:
			case TV_BOW:
			case TV_ARROW:
			case TV_MAIL:
			case TV_SOFT_ARMOR:
			case TV_SHIELD:
			case TV_HELM:
			case TV_CROWN:
			case TV_CLOAK:
			case TV_GLOVES:
			case TV_BOOTS:
			case TV_LIGHT:
			{
				if (!o_ptr->name1 && !o_ptr->name2)
				{
					/* Identify it */
					object_aware(o_ptr);
					object_known(o_ptr);
					break;
				}
			}
			default:
			{
				if (!(k_ptr->flags3 & (TR3_EASY_KNOW)))
				{
					o_ptr->ident &= ~(IDENT_KNOWN);
				}
			}
		}
		
		/* Hack -- Clear the "empty" flag */
		o_ptr->ident &= ~(IDENT_EMPTY);
		
		// re pseudo id
		pseudo_id(o_ptr);
	}

	/* Forget info about carried objects */
	for (i = 0; i < INVEN_TOTAL; i++)
	{
		object_type *o_ptr = &inventory[i];
		object_kind *k_ptr = &k_info[o_ptr->k_idx];
		
		/* Skip non-objects */
		if (!o_ptr->k_idx) continue;
		
		// identify non-special non-artefact weapons/armour		
		switch (o_ptr->tval)
		{
			case TV_DIGGING:
			case TV_HAFTED:
			case TV_POLEARM:
			case TV_SWORD:
			case TV_BOW:
			case TV_ARROW:
			case TV_MAIL:
			case TV_SOFT_ARMOR:
			case TV_SHIELD:
			case TV_HELM:
			case TV_CROWN:
			case TV_CLOAK:
			case TV_GLOVES:
			case TV_BOOTS:
			case TV_LIGHT:
			{
				if (!o_ptr->name1 && !o_ptr->name2)
				{
					/* Identify it */
					object_aware(o_ptr);
					object_known(o_ptr);
					break;
				}
			}
			default:
			{
				if (!(k_ptr->flags3 & (TR3_EASY_KNOW)))
				{
					o_ptr->ident &= ~(IDENT_KNOWN);
				}
			}
		}
				
		/* Hack -- Clear the "empty" flag */
		o_ptr->ident &= ~(IDENT_EMPTY);

		// re pseudo id
		pseudo_id(o_ptr);
	}
	
	/* Reset the object kinds */
	for (i = 1; i < z_info->k_max; i++)
	{
		object_kind *k_ptr = &k_info[i];
		
		/* Reset "tried" */
		k_ptr->tried = FALSE;
		
		/* Reset "aware" */
		k_ptr->aware = FALSE;
	}

	/* Reset the special objects */
	for (i = 1; i < z_info->e_max; i++)
	{
		ego_item_type *e_ptr = &e_info[i];
		
		/* Reset "aware" */
		e_ptr->aware = FALSE;
	}

	/* Forget encountered monsters */
	for (i = 1; i < mon_max; i++)
	{
		monster_type *m_ptr = &mon_list[i];
		
		m_ptr->encountered = FALSE;
	}
		
	/* Reset the monster memory */
	for (i = 1; i < z_info->r_max; i++)
	{
		monster_lore *l_ptr = &l_list[i];
		
		WIPE(l_ptr, monster_lore);
	}

	/* Mega-Hack -- Forget the map */
	wiz_dark();

	// lose all spare experience
	//lose_exp(10000);
	
	// clear the cheat flags
	p_ptr->noscore = 0x0000;
	
	/* Forget turns */
	turn = 1;
	playerturn = 1;

	// forget all messages -- currently a bit buggy
	messages_init();
	
	// clear target
	target_set_monster(0);
	
	/* Recalculate bonuses */
	p_ptr->update |= (PU_BONUS);
	
	/* Combine / Reorder the pack (later) */
	p_ptr->notice |= (PN_COMBINE | PN_REORDER);
	
	/* Window stuff */
	p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER_0);
	
}
예제 #6
0
파일: init2.c 프로젝트: cinereaste/angband
/*
 * Initialize some other arrays
 */
static errr init_other(void)
{
	int i;


	/*** Prepare the various "bizarre" arrays ***/

	/* Initialize the "macro" package */
	(void)macro_init();

	/* Initialize the "quark" package */
	(void)quarks_init();

	/* Initialize squelch things */
	autoinscribe_init();
	squelch_init();
	init_cmd_know();

	/* Initialize the "message" package */
	(void)messages_init();

	/*** Prepare grid arrays ***/

	/* Array of grids */
	view_g = C_ZNEW(VIEW_MAX, u16b);

	/* Array of grids */
	temp_g = C_ZNEW(TEMP_MAX, u16b);

	/* Hack -- use some memory twice */
	temp_y = ((byte*)(temp_g)) + 0;
	temp_x = ((byte*)(temp_g)) + TEMP_MAX;


	/*** Prepare dungeon arrays ***/

	/* Padded into array */
	cave_info = C_ZNEW(DUNGEON_HGT, byte_256);
	cave_info2 = C_ZNEW(DUNGEON_HGT, byte_256);

	/* Feature array */
	cave_feat = C_ZNEW(DUNGEON_HGT, byte_wid);

	/* Entity arrays */
	cave_o_idx = C_ZNEW(DUNGEON_HGT, s16b_wid);
	cave_m_idx = C_ZNEW(DUNGEON_HGT, s16b_wid);

	/* Flow arrays */
	cave_cost = C_ZNEW(DUNGEON_HGT, byte_wid);
	cave_when = C_ZNEW(DUNGEON_HGT, byte_wid);


	/*** Prepare "vinfo" array ***/

	/* Used by "update_view()" */
	(void)vinfo_init();


	/*** Prepare entity arrays ***/

	/* Objects */
	o_list = C_ZNEW(z_info->o_max, object_type);

	/* Monsters */
	mon_list = C_ZNEW(z_info->m_max, monster_type);


	/*** Prepare lore array ***/

	/* Lore */
	l_list = C_ZNEW(z_info->r_max, monster_lore);


	/*** Prepare mouse buttons ***/

	button_init(button_add_text, button_kill_text);


	/*** Prepare quest array ***/

	/* Quests */
	q_list = C_ZNEW(MAX_Q_IDX, quest);


	/*** Prepare the inventory ***/

	/* Allocate it */
	inventory = C_ZNEW(ALL_INVEN_TOTAL, object_type);



	/*** Prepare the options ***/
	option_set_defaults();

	/* Initialize the window flags */
	for (i = 0; i < ANGBAND_TERM_MAX; i++)
	{
		/* Assume no flags */
		op_ptr->window_flag[i] = 0L;
	}


	/*** Pre-allocate space for the "format()" buffer ***/

	/* Hack -- Just call the "format()" function */
	(void)format("I wish you could swim, like dolphins can swim...");


	/* Success */
	return (0);
}
예제 #7
0
/*
 * Initialize some other arrays
 */
static errr init_other(void)
{
	int i;

	/*** Prepare the various "bizarre" arrays ***/

	/* Initialize the "macro" package */
	(void)macro_init();

	/* Initialize the "quark" package */
	(void)quarks_init();

	/* Initialize squelch things */
	autoinscribe_init();
	init_cmd_know();

	/* Initialize the "message" package */
	(void)messages_init();

	/*** Prepare grid arrays ***/

	/* Array of grids */
	view_g = C_ZNEW(VIEW_MAX, u16b);

	/* Array of grids */
	temp_g = C_ZNEW(TEMP_MAX, u16b);

	/* Hack -- use some memory twice */
	temp_y = ((byte*)(temp_g)) + 0;
	temp_x = ((byte*)(temp_g)) + TEMP_MAX;

	/* Array of grids */
	fire_g = C_ZNEW(VIEW_MAX, u16b);

	/* has_LIGHT patch causes both temp_g and temp_x/y to be used
	   in targetting mode: can't use the same memory any more. */
	temp_y = C_ZNEW(TEMP_MAX, byte);
	temp_x = C_ZNEW(TEMP_MAX, byte);

	/* Array of dynamic grids */
	dyna_g = C_ZNEW(DYNA_MAX, dynamic_grid_type);

	/* Array of stacked monster messages */
	mon_msg = C_ZNEW(MAX_STORED_MON_MSG, monster_race_message);
	mon_message_hist = C_ZNEW(MAX_STORED_MON_CODES, monster_message_history);

	/* Prepare monster movement array*/
	mon_moment_info = C_ZNEW(z_info->m_max, move_moment_type);

	/*** Prepare dungeon arrays ***/

	/* Padded into array */
	cave_info = C_ZNEW(MAX_DUNGEON_HGT, u16b_256);

	/* Feature array */
	cave_feat = C_ZNEW(MAX_DUNGEON_HGT, byte_wid);

	/* Entity arrays */
	cave_o_idx = C_ZNEW(MAX_DUNGEON_HGT, s16b_wid);
	cave_m_idx = C_ZNEW(MAX_DUNGEON_HGT, s16b_wid);
	cave_x_idx = C_ZNEW(MAX_DUNGEON_HGT, s16b_wid);

#ifdef MONSTER_SMELL

	/* Flow arrays */
	cave_when = C_ZNEW(MAX_DUNGEON_HGT, byte_wid);

#endif /* MONSTER_SMELL */

	/*start with cost at center 0*/
	for (i = 0; i < MAX_FLOWS; i++)
	{
		cost_at_center[i] = 0;
	}


	/*** Prepare "vinfo" array ***/

	/* Used by "update_view()" */
	(void)vinfo_init();


	/*** Prepare entity arrays ***/

	/* Objects */
	o_list = C_ZNEW(z_info->o_max, object_type);

	/* Monsters */
	mon_list = C_ZNEW(z_info->m_max, monster_type);

	/* Effects */
	x_list = C_ZNEW(z_info->x_max, effect_type);


	/*** Prepare mosnter lore array ***/

	/* Lore */
	l_list = C_ZNEW(z_info->r_max, monster_lore);

	/*** Prepare terrain lore array ***/

	/* Lore */
	f_l_list = C_ZNEW(z_info->f_max, feature_lore);

	/*** Prepare artifact lore array ***/

    /* Lore */
    a_l_list = C_ZNEW(z_info->art_max, artifact_lore);

	/*** Prepare mouse buttons ***/

	button_init(button_add_text, button_kill_text);

	/*** Prepare the inventory ***/

	/* Allocate it */
	inventory = C_ZNEW(ALL_INVEN_TOTAL, object_type);


	/*** Prepare the stores ***/

	/* Allocate the stores */
	store = C_ZNEW(MAX_STORES, store_type);

	/* Fill in each store */
	for (i = 0; i < MAX_STORES; i++)
	{

		/* Get the store */
		store_type *st_ptr = &store[i];

		/* Assume full stock */
		st_ptr->stock_size = STORE_INVEN_MAX;

		/* Allocate the stock */
		st_ptr->stock = C_ZNEW(st_ptr->stock_size, object_type);

	}


	/*** Prepare the options ***/

	/* Initialize the options */
	for (i = 0; i < OPT_MAX; i++)
	{
		/* Default value */
		op_ptr->opt[i] = options[i].normal;
	}

	/* Initialize the window flags */
	for (i = 0; i < ANGBAND_TERM_MAX; i++)
	{
		/* Assume no flags */
		op_ptr->window_flag[i] = 0L;
	}

	/*Clear the update flags*/
	p_ptr->notice = 0L;
	p_ptr->update = 0L;
	p_ptr->redraw = 0L;


	/*** Pre-allocate space for the "format()" buffer ***/

	/* Hack -- Just call the "format()" function */
	(void)format("%s", MAINTAINER);


	/* Success */
	return (0);
}
예제 #8
0
int 
main(int argc, char *argv[])
{
    /* If the arguments are not entered correctly then exit the program with proper instruction */
    if ( argc != 3 )
    {
        printf("Please enter the proper argument i.e: %s users.txt tickets.txt \n", argv[0] );
    }
    else{
        int i;
        pthread_t threads[4];
        pthread_attr_t attr;
        thread_ids_t threadids;  /* creating threadids to store ids of all threads and pass it to the client thread*/
        int     count = 0;

        read_auth_file(argv[1]);
        read_ticket_file(argv[2]);


        /* Don't start if we can't get the message system working. */
        if (messages_init() == MSG_OK) {
            /* Initialize mutex and condition variable objects */
            pthread_mutex_init(&print_lock, NULL);
            pthread_cond_init (&count_threshold_cv, NULL);

            /* For portability, explicitly create threads in a joinable state */
            pthread_attr_init(&attr);
            pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);

            /* Creating threads in joinable state*/

            pthread_create(&threads[1], &attr, server, NULL); 
            threadids.server_thread_id = threads[1];
            pthread_create(&threads[2], &attr, auth_thread, NULL);
            threadids.auth_thread_id = threads[2];
            pthread_create(&threads[3], &attr, ticket_thread, NULL);   
            threadids.ticket_thread_id = threads[3];
            pthread_create(&threads[0], &attr, client, (void *)&threadids); 

            /* Wait for all threads to complete */
            for (i = 0; i < NUM_THREADS; i++) {
            pthread_join(threads[i], NULL);
            }
            printf ("Main(): Waited on %d threads. Final value of count = %d. Done.\n", 
                    NUM_THREADS, count);

            /* Clean up and exit */
            pthread_attr_destroy(&attr);
            pthread_mutex_destroy(&print_lock);
            pthread_cond_destroy(&count_threshold_cv);
            pthread_exit (NULL);
            /* Clean up the message system. */

            messages_end();
        }
        else
        {
            printf ("Message system doesn't work!\n");
        }
    }
    
    printf("Exiting the main program...\n");
    return 0;
}