blob: 9d8debb1daf4083fdad48ec378a79a5766d1d36a [file] [log] [blame]
// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SERVICE_SORTER_
#define SERVICE_SORTER_
#include <vector>
#include "shill/refptr_types.h"
#include "shill/service.h"
namespace shill {
class Manager;
// This is a closure used by the Manager for STL sorting of the
// Service array. We pass instances of this object to STL sort(),
// which in turn will call the selected function in the Manager to
// compare two Service objects at a time.
class ServiceSorter {
public:
ServiceSorter(bool compare_connectivity_state,
const std::vector<Technology::Identifier> &tech_order)
: compare_connectivity_state_(compare_connectivity_state),
technology_order_(tech_order) {}
bool operator() (ServiceRefPtr a, ServiceRefPtr b) {
const char *reason;
return Service::Compare(a, b, compare_connectivity_state_,
technology_order_, &reason);
}
private:
const bool compare_connectivity_state_;
const std::vector<Technology::Identifier> &technology_order_;
// We can't DISALLOW_COPY_AND_ASSIGN since this is passed by value to STL
// sort.
};
} // namespace shill
#endif // SERVICE_SORTER_