shill: Implement service sorting

Sort the list of Services for presentation to
RPC callers, essentially copying the current flimflam
sorting criteria.  Introduce the TechnologyOrder to
the Manager.

BUG=chromium-os:20114
TEST=New unit tests

Change-Id: I766b2297ba3170a7a6ab5adfe68425a8011be4fb
Reviewed-on: http://gerrit.chromium.org/gerrit/8205
Tested-by: Paul Stewart <pstew@chromium.org>
Reviewed-by: mukesh agrawal <quiche@chromium.org>
diff --git a/service_sorter.h b/service_sorter.h
new file mode 100644
index 0000000..7707a17
--- /dev/null
+++ b/service_sorter.h
@@ -0,0 +1,36 @@
+// Copyright (c) 2011 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:
+  explicit ServiceSorter(const std::vector<Technology::Identifier> &tech_order)
+      : technology_order_(tech_order) {}
+  bool operator() (ServiceRefPtr a, ServiceRefPtr b) {
+    return Service::Compare(a, b, technology_order_);
+  }
+
+ private:
+  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_