blob: 9d8debb1daf4083fdad48ec378a79a5766d1d36a [file] [log] [blame]
mukesh agrawalddc378f2012-02-17 18:26:20 -08001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Paul Stewart22aa71b2011-09-16 12:15:11 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef SERVICE_SORTER_
6#define SERVICE_SORTER_
7
8#include <vector>
9
10#include "shill/refptr_types.h"
11#include "shill/service.h"
12
13namespace shill {
14
15class Manager;
16
17// This is a closure used by the Manager for STL sorting of the
18// Service array. We pass instances of this object to STL sort(),
19// which in turn will call the selected function in the Manager to
20// compare two Service objects at a time.
21class ServiceSorter {
22 public:
Paul Stewart39db5ca2013-03-18 14:15:17 -070023 ServiceSorter(bool compare_connectivity_state,
24 const std::vector<Technology::Identifier> &tech_order)
25 : compare_connectivity_state_(compare_connectivity_state),
26 technology_order_(tech_order) {}
Paul Stewart22aa71b2011-09-16 12:15:11 -070027 bool operator() (ServiceRefPtr a, ServiceRefPtr b) {
mukesh agrawalddc378f2012-02-17 18:26:20 -080028 const char *reason;
Paul Stewart39db5ca2013-03-18 14:15:17 -070029 return Service::Compare(a, b, compare_connectivity_state_,
30 technology_order_, &reason);
Paul Stewart22aa71b2011-09-16 12:15:11 -070031 }
32
33 private:
Paul Stewart39db5ca2013-03-18 14:15:17 -070034 const bool compare_connectivity_state_;
Paul Stewart22aa71b2011-09-16 12:15:11 -070035 const std::vector<Technology::Identifier> &technology_order_;
Paul Stewart39db5ca2013-03-18 14:15:17 -070036 // We can't DISALLOW_COPY_AND_ASSIGN since this is passed by value to STL
37 // sort.
Paul Stewart22aa71b2011-09-16 12:15:11 -070038};
39
40} // namespace shill
41
42#endif // SERVICE_SORTER_