Partilhar via


Usar uma lista de rotas Client-Specific

Os procedimentos a seguir descrevem as etapas para usar as listas de rotas específicas do cliente. O código de exemplo a seguir mostra como implementar o procedimento.

Para usar esse recurso, um cliente deve seguir as etapas a seguir

  1. Chame RtmCreateRouteList para obter um identificador do gerenciador de tabelas de roteamento.
  2. Chame RtmInsertInRouteList sempre que o cliente precisar adicionar uma rota a essa lista.
  3. Quando o cliente não exigir mais a lista, ele deverá chamar RtmDeleteRouteList para remover a lista.

Se o cliente precisar enumerar as rotas na lista, o cliente deverá seguir as etapas a seguir

  1. Chame RtmCreateRouteListEnum para obter um identificador de enumeração do gerenciador de tabelas de roteamento.
  2. Chame RtmGetListEnumRoutes para obter os identificadores para as rotas na lista.
  3. Chame RtmReleaseRoutes para liberar os identificadores quando não forem mais necessários.

O código de exemplo a seguir mostra como criar e usar uma lista de rotas específica do cliente.

HANDLE RouteListHandle1;
HANDLE RouteListHandle2;

// Create two entity-specific lists to add routes to

Status = RtmCreateRouteList(RtmRegHandle,
                            &RouteListHandle1);
// Check Status
//...

Status = RtmCreateRouteList(RtmRegHandle,
                            &RouteListHandle2);
// Check Status
//...

// Assume you have added a bunch of routes
// by calling RtmAddRouteToDest many times
// with 'RouteListHandle1' specified similar to
// Status = RtmAddRouteToDest(RtmRegHandle,
//                            ...
//                            RouteListHandle1,
//                            ...
//                            &ChangeFlags);

// Enumerate routes in RouteListHandle1 list

// Create an enumeration on the route list

Status = RtmCreateRouteListEnum(RtmRegHandle,
                                RouteListHandle1,
                                &EnumHandle);

if (Status == NO_ERROR)
{
        // Allocate space on the top of the stack
        
    MaxHandles = RegnProfile.MaxHandlesInEnum;

    RouteHandles = _alloca(MaxHandles * sizeof(HANDLE));

    // Note how the termination condition is different
    // from other enumerations - the call to the function
    // RtmGetListEnumRoutes always returns NO_ERROR
    // Quit when you get fewer handles than requested
    
    do
    {
                // Get next set of routes from the list enumeration
        
        NumHandles = MaxHandles;

        Status = RtmGetListEnumRoutes(RtmRegHandle,
                                      EnumHandle,
                                      &NumHandles,
                                      RouteHandles);

        for (i = 0; i < NumHandles; i++)
        {
            Print("Route Handle %5lu: %p\n", i, RouteHandles[i]);
        }

        // Move all these routes to another route list
        // They are automatically removed from the old one
        
        Status = RtmInsertInRouteList(RtmRegHandle,
                                      RouteListHandle2,
                                      NumHandles,
                                      RouteHandles);
        // Check Status...
        
                // Release the routes that have been enumerated
        
        RtmReleaseRoutes(RtmRegHandle, NumHandles, RouteHandles);
    }
    while (NumHandles == MaxHandles);

    RtmDeleteEnumHandle(RtmRegHandle, EnumHandle);
}

// Destroy all the entity-specific route lists 
// after removing all routes from these lists;
// the routes themselves are not deleted

Status = RtmDeleteRouteList(RtmRegHandle, RouteListHandle1);
ASSERT(Status == NO_ERROR);


Status = RtmDeleteRouteList(RtmRegHandle, RouteListHandle2);
ASSERT(Status == NO_ERROR);