Пример #1
0
void MvcpThread::do_uls(mvcp amvcp, QObject* parameters)
{
    delete parameters;
    mvcp_units units = mvcp_units_init(amvcp);
    QStringList unitList;
    for (int i = 0; i < mvcp_units_count(units); i++) {
        mvcp_unit_entry_t unit;
        mvcp_units_get(units, i, &unit);
        unitList << QString::fromUtf8(unit.guid);
    }
    mvcp_units_close(units);
    emit ulsResult(unitList);
}
Пример #2
0
mvcp_error_code client_select_unit( client demo )
{
	int terminated = 0;
	int refresh = 1;

	while ( !terminated )
	{
		mvcp_units units = mvcp_units_init( demo->dv );

		if ( mvcp_units_count( units ) > 0 )
		{
			mvcp_unit_entry_t unit;
			int index = 0;
			char key = '\0';

			if ( refresh )
			{
				printf( "Select a Unit\n\n" );

				for ( index = 0; index < mvcp_units_count( units ); index ++ )
				{
					mvcp_units_get( units, index, &unit );
					printf( "%d: U%d - %s [%s]\n", index + 1, 
												   unit.unit, 
												   unit.guid, 
												   unit.online ? "online" : "offline" );
				}
				printf( "0: Exit\n\n" );

				printf( "Unit [%d]: ", demo->selected_unit + 1 );
				refresh = 0;
			}

			key = get_keypress( );

			if ( key == '\r' )
				key = demo->selected_unit + '1';

			if ( key != '0' )
			{
				if ( key >= '1' && key < '1' + mvcp_units_count( units ) )
				{
					demo->selected_unit = key - '1';
					printf( "%c\n\n", key );
					client_load( demo );
					refresh = 1;
				}
				else
				{
					beep( );
				}					
			}
			else
			{
				printf( "0\n\n" );
				terminated = 1;
			}
		}
		else if ( mvcp_units_count( units ) == 0 )
		{
			printf( "No units added - add a unit first\n\n" );
			client_add_unit( demo );
		}
		else
		{
			printf( "Unable to obtain Unit List.\n" );
			terminated = 1;
		}

		mvcp_units_close( units );
	}

	return mvcp_ok;
}
Пример #3
0
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;
}