-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontext.cc
57 lines (43 loc) · 1.42 KB
/
context.cc
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
// Copyright (c) 2013 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.
#include "mist/context.h"
#include <brillo/udev/udev.h>
#include "mist/config_loader.h"
#include "mist/event_dispatcher.h"
#include "mist/metrics.h"
#include "mist/usb_device_event_notifier.h"
#include "mist/usb_manager.h"
namespace mist {
Context::Context() = default;
Context::~Context() = default;
bool Context::Initialize() {
metrics_.reset(new Metrics());
CHECK(metrics_);
config_loader_.reset(new ConfigLoader());
CHECK(config_loader_);
if (!config_loader_->LoadDefaultConfig()) {
LOG(ERROR) << "Could not load default config file.";
return false;
}
event_dispatcher_.reset(new EventDispatcher());
CHECK(event_dispatcher_);
udev_ = brillo::Udev::Create();
if (!udev_) {
LOG(ERROR) << "Could not create udev library context.";
return false;
}
usb_device_event_notifier_ =
std::make_unique<UsbDeviceEventNotifier>(udev_.get());
if (!usb_device_event_notifier_->Initialize()) {
LOG(ERROR) << "Could not initialize USB device event notification.";
return false;
}
usb_manager_.reset(new UsbManager(event_dispatcher_.get()));
if (!usb_manager_->Initialize()) {
LOG(ERROR) << "Could not initialize USB manager: " << usb_manager_->error();
return false;
}
return true;
}
} // namespace mist