コード例 #1
0
ファイル: view.cpp プロジェクト: aurelioarranz/hermes
void View::wait(ViewWaitEvent wait_event, const char* text) {
  //prepare message
  std::stringstream str;
  str << "  << ";
  if (text != NULL)
    str << text;
  else {
    switch(wait_event) {
      case HERMES_WAIT_CLOSE: str << HERMES_WAIT_CLOSE_MSG; break;
      case HERMES_WAIT_KEYPRESS: str << HERMES_WAIT_KEYPRESS_MSG; break;
      default: error("Unknown wait event"); break;
    }
  }
  str << " >>" << std::endl;

  //do something
  switch(wait_event) {
    case HERMES_WAIT_CLOSE: wait_for_all_views_close(str.str().c_str()); break;
    case HERMES_WAIT_KEYPRESS: wait_for_any_key(str.str().c_str()); break;
    default: error("Unknown wait event"); break;
  }
}
コード例 #2
0
ファイル: client.c プロジェクト: gz818/melted
mvcp_error_code client_add_unit( client demo )
{
	mvcp_error_code error = mvcp_ok;
	mvcp_nodes nodes = mvcp_nodes_init( demo->dv );
	mvcp_units units = mvcp_units_init( demo->dv );

	if ( mvcp_nodes_count( nodes ) != -1 && mvcp_units_count( units ) != -1 )
	{
		char pressed;
		mvcp_node_entry_t node;
		mvcp_unit_entry_t unit;
		int node_index = 0;
		int unit_index = 0;

		printf( "Select a Node\n\n" );

		for ( node_index = 0; node_index < mvcp_nodes_count( nodes ); node_index ++ )
		{
			mvcp_nodes_get( nodes, node_index, &node );
			printf( "%d: %s - %s ", node_index + 1, node.guid, node.name );
			for ( unit_index = 0; unit_index < mvcp_units_count( units ); unit_index ++ )
			{
				mvcp_units_get( units, unit_index, &unit );
				if ( !strcmp( unit.guid, node.guid ) )
					printf( "[U%d] ", unit.unit );
			}
			printf( "\n" );
		}

		printf( "0. Exit\n\n" );

		printf( "Node: " );

		while ( ( pressed = get_keypress( ) ) != '0' )
		{
			node_index = pressed - '1';
			if ( node_index >= 0 && node_index < mvcp_nodes_count( nodes ) )
			{
				int unit;
				printf( "%c\n\n", pressed );
				mvcp_nodes_get( nodes, node_index, &node );
				if ( mvcp_unit_add( demo->dv, node.guid, &unit ) == mvcp_ok )
				{
					printf( "Unit added as U%d\n", unit );
					demo->selected_unit = unit;
				}
				else
				{
					int index = 0;
					mvcp_response response = mvcp_get_last_response( demo->dv );
					printf( "Failed to add unit:\n\n" );
					for( index = 1; index < mvcp_response_count( response ) - 1; index ++ )
						printf( "%s\n", mvcp_response_get_line( response, index ) );
				}
				printf( "\n" );
				wait_for_any_key( NULL );
				break;
			}
			else
			{
				beep( );
			}
		}
	}
	else
	{
		printf( "Invalid response from the server.\n\n" );
		wait_for_any_key( NULL );
	}

	mvcp_nodes_close( nodes );
	mvcp_units_close( units );

	return error;
}