summaryrefslogtreecommitdiffstats
path: root/mojo/shell/public/cpp/lib/capabilities.cc
blob: add91505cbcf9d21056c8c8cfceddb71d96583e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "mojo/shell/public/cpp/capabilities.h"

namespace mojo {

CapabilityRequest::CapabilityRequest() {}
CapabilityRequest::~CapabilityRequest() {}

bool CapabilityRequest::operator==(const CapabilityRequest& other) const {
  return other.classes == classes && other.interfaces == interfaces;
}

bool CapabilityRequest::operator<(const CapabilityRequest& other) const {
  return std::tie(classes, interfaces) <
      std::tie(other.classes, other.interfaces);
}

CapabilitySpec::CapabilitySpec() {}
CapabilitySpec::~CapabilitySpec() {}

bool CapabilitySpec::operator==(const CapabilitySpec& other) const {
  return other.provided == provided && other.required == required;
}

bool CapabilitySpec::operator<(const CapabilitySpec& other) const {
  return std::tie(provided, required) <
      std::tie(other.provided, other.required);
}

// static
shell::mojom::CapabilitySpecPtr
TypeConverter<shell::mojom::CapabilitySpecPtr, CapabilitySpec>::Convert(
    const CapabilitySpec& input) {
  shell::mojom::CapabilitySpecPtr spec(shell::mojom::CapabilitySpec::New());
  spec->provided =
      mojo::Map<mojo::String, mojo::Array<mojo::String>>::From(input.provided);
  spec->required =
      mojo::Map<mojo::String, shell::mojom::CapabilityRequestPtr>::From(
          input.required);
  return spec;
}

// static
CapabilitySpec
TypeConverter<CapabilitySpec, shell::mojom::CapabilitySpecPtr>::Convert(
    const shell::mojom::CapabilitySpecPtr& input) {
  CapabilitySpec spec;
  spec.provided = input->provided.To<std::map<Class, Interfaces>>();
  spec.required =
      input->required.To<std::map<Name, CapabilityRequest>>();
  return spec;
}

// static
shell::mojom::CapabilityRequestPtr
TypeConverter<shell::mojom::CapabilityRequestPtr,
              CapabilityRequest>::Convert(
    const CapabilityRequest& input) {
  shell::mojom::CapabilityRequestPtr request(
      shell::mojom::CapabilityRequest::New());
  request->classes = mojo::Array<mojo::String>::From(input.classes);
  request->interfaces = mojo::Array<mojo::String>::From(input.interfaces);
  return request;
}

// static
CapabilityRequest
TypeConverter<CapabilityRequest,
              shell::mojom::CapabilityRequestPtr>::Convert(
    const shell::mojom::CapabilityRequestPtr& input) {
  CapabilityRequest request;
  request.classes = input->classes.To<std::set<std::string>>();
  request.interfaces = input->interfaces.To<std::set<std::string>>();
  return request;
}

}  // namespace mojo