1 //
2 // Copyright (C) 2012 The Android Open Source Project
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #ifndef SHILL_SERVICE_SORTER_H_
18 #define SHILL_SERVICE_SORTER_H_
19 
20 #include <vector>
21 
22 #include "shill/refptr_types.h"
23 #include "shill/service.h"
24 
25 namespace shill {
26 
27 class Manager;
28 
29 // This is a closure used by the Manager for STL sorting of the
30 // Service array.  We pass instances of this object to STL sort(),
31 // which in turn will call the selected function in the Manager to
32 // compare two Service objects at a time.
33 class ServiceSorter {
34  public:
ServiceSorter(Manager * manager,bool compare_connectivity_state,const std::vector<Technology::Identifier> & tech_order)35   ServiceSorter(Manager* manager,
36                 bool compare_connectivity_state,
37                 const std::vector<Technology::Identifier>& tech_order)
38       : manager_(manager),
39         compare_connectivity_state_(compare_connectivity_state),
40         technology_order_(tech_order) {}
operator()41   bool operator() (ServiceRefPtr a, ServiceRefPtr b) {
42     const char* reason;
43     return Service::Compare(manager_, a, b, compare_connectivity_state_,
44                             technology_order_, &reason);
45   }
46 
47  private:
48   Manager* manager_;
49   const bool compare_connectivity_state_;
50   const std::vector<Technology::Identifier>& technology_order_;
51   // We can't DISALLOW_COPY_AND_ASSIGN since this is passed by value to STL
52   // sort.
53 };
54 
55 }  // namespace shill
56 
57 #endif  // SHILL_SERVICE_SORTER_H_
58