C/C++ API Reference
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 {
24
26
28namespace system {
29
30class AsyncCore; // Forward declaration for function declaration.
31
32} // namespace system
33
38
41[[noreturn]] void SystemStart(channel::ByteReaderWriter& io_channel);
42
43namespace system {
44
47class AsyncCore {
48 public:
51
54
56 rpc::Server& rpc_server() { return rpc_server_; }
57
63 [[nodiscard]] bool RunOnce(Function<void()>&& function);
64
65 private:
66 friend AsyncCore& pw::System();
68
69 explicit _PW_RPC_CONSTEXPR AsyncCore()
70 : rpc_channels_{}, rpc_server_(rpc_channels_) {}
71
72 void Init(channel::ByteReaderWriter& io_channel);
73
74 static async2::Poll<> InitTask(async2::Context&);
75
76 rpc::Channel rpc_channels_[1];
77 rpc::Server rpc_server_;
78};
79
80} // namespace system
81
83 _PW_RPC_CONSTINIT static system::AsyncCore system_core;
84 return system_core;
85}
86
87} // namespace pw
Definition: allocator.h:36
Definition: context.h:55
A single-threaded cooperatively scheduled runtime for async tasks.
Definition: dispatcher.h:48
Definition: poll.h:60
Definition: channel.h:55
Definition: channel.h:247
Definition: system.h:47
fit::function_impl< function_internal::config::kInlineCallableSize, !function_internal::config::kEnableDynamicAllocation, FunctionType, PW_FUNCTION_DEFAULT_ALLOCATOR_TYPE > Function
Definition: function.h:73
Allocator & allocator()
Returns the system pw::Allocator instance.
void SystemStart(channel::ByteReaderWriter &io_channel)
rpc::Server & rpc_server()
Returns the system pw::rpc::Server instance.
Definition: system.h:56
async2::Dispatcher & dispatcher()
Returns the system pw::async2::Dispatcher instance.
bool RunOnce(Function< void()> &&function)
system::AsyncCore & System()
Definition: system.h:82
The Pigweed namespace.
Definition: alignment.h:27