Pigweed
C/C++ API Reference
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
system.h
1// Copyright 2024 The Pigweed Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4// use this file except in compliance with the License. You may obtain a copy of
5// the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12// License for the specific language governing permissions and limitations under
13// the License.
14#pragma once
15
16#include <tuple>
17
18#include "pw_allocator/allocator.h"
19#include "pw_channel/channel.h"
20#include "pw_function/function.h"
21#include "pw_rpc/server.h"
22
23namespace pw {
24namespace system {
25
26class AsyncCore; // Forward declaration for function declaration.
27
28} // namespace system
29
33system::AsyncCore& System();
34
37[[noreturn]] void SystemStart(channel::ByteReaderWriter& io_channel);
38
39namespace system {
40
43class AsyncCore {
44 public:
47
50
52 rpc::Server& rpc_server() { return rpc_server_; }
53
59 [[nodiscard]] bool RunOnce(Function<void()>&& function);
60
61 private:
62 friend AsyncCore& pw::System();
64
65 explicit _PW_RPC_CONSTEXPR AsyncCore()
66 : rpc_channels_{}, rpc_server_(rpc_channels_) {}
67
68 void Init(channel::ByteReaderWriter& io_channel);
69
70 static async2::Poll<> InitTask(async2::Context&);
71
72 rpc::Channel rpc_channels_[1];
73 rpc::Server rpc_server_;
74};
75
76} // namespace system
77
79 _PW_RPC_CONSTINIT static system::AsyncCore system_core;
80 return system_core;
81}
82
83} // namespace pw
Definition: allocator.h:34
Definition: context.h:49
A single-threaded cooperatively-scheduled runtime for async tasks.
Definition: dispatcher.h:46
Definition: poll.h:54
Definition: channel.h:56
Definition: channel.h:235
Definition: system.h:43
Allocator & allocator()
Returns the system pw::Allocator instance.
rpc::Server & rpc_server()
Returns the system pw::rpc::Server instance.
Definition: system.h:52
async2::Dispatcher & dispatcher()
Returns the system pw::async2::Dispatcher instance.
bool RunOnce(Function< void()> &&function)
fit::function_impl< function_internal::config::kInlineCallableSize, !function_internal::config::kEnableDynamicAllocation, FunctionType, PW_FUNCTION_DEFAULT_ALLOCATOR_TYPE > Function
Definition: function.h:74
Provides basic helpers for reading and writing UTF-8 encoded strings.
Definition: alignment.h:27
void SystemStart(channel::ByteReaderWriter &io_channel)
system::AsyncCore & System()
Definition: system.h:78