ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Context.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
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#include "hermes/core/Context.h"
18
19#include <cassert>
20
21namespace hermes
22{
23
24const Config *Context::config(void) const
25{
26 // Return the current configuration
27 return _config.get();
28}
29
30void Context::config(std::unique_ptr<Config> &&config)
31{
32 _config = std::move(config);
33
34 // Apply updated configurations
35 for (auto source : _sources)
36 {
37 source->reload(_config.get());
38 }
39}
40
41void Context::post(std::unique_ptr<Message> &&msg)
42{
43 // Validate message
44 assert((msg != nullptr) && "invalid message");
45 assert((msg->text() != nullptr) && "missing text");
46
47 // Take the ownership of a given message
48 auto m = std::move(msg);
49
50 // Notify appended sinks
51 for (const auto &sink : _sinks)
52 {
53 sink->notify(m.get());
54 }
55
56 // TODO Stop the process if "FATAL" message is posted
57}
58
59void Context::attach(Source *source)
60{
61 // Configure source first
62 source->reload(config());
63 // Insert source
64 _sources.insert(source);
65}
66
67void Context::detach(Source *source)
68{
69 // Remove source
70 _sources.erase(source);
71}
72
73void Context::append(std::unique_ptr<Sink> &&sink)
74{
75 // Append sink
76 _sinks.insert(std::move(sink));
77}
78
79} // namespace hermes
const Config * config(void) const
Get the global configuration.
Definition Context.cpp:24
Top-level configuration interface.
Definition Config.h:35