mukesh agrawal | ddc378f | 2012-02-17 18:26:20 -0800 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 2 | // 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 | |
| 13 | namespace shill { |
| 14 | |
| 15 | class 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. |
| 21 | class ServiceSorter { |
| 22 | public: |
Paul Stewart | 39db5ca | 2013-03-18 14:15:17 -0700 | [diff] [blame] | 23 | 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 Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 27 | bool operator() (ServiceRefPtr a, ServiceRefPtr b) { |
mukesh agrawal | ddc378f | 2012-02-17 18:26:20 -0800 | [diff] [blame] | 28 | const char *reason; |
Paul Stewart | 39db5ca | 2013-03-18 14:15:17 -0700 | [diff] [blame] | 29 | return Service::Compare(a, b, compare_connectivity_state_, |
| 30 | technology_order_, &reason); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | private: |
Paul Stewart | 39db5ca | 2013-03-18 14:15:17 -0700 | [diff] [blame] | 34 | const bool compare_connectivity_state_; |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 35 | const std::vector<Technology::Identifier> &technology_order_; |
Paul Stewart | 39db5ca | 2013-03-18 14:15:17 -0700 | [diff] [blame] | 36 | // We can't DISALLOW_COPY_AND_ASSIGN since this is passed by value to STL |
| 37 | // sort. |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 38 | }; |
| 39 | |
| 40 | } // namespace shill |
| 41 | |
| 42 | #endif // SERVICE_SORTER_ |