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
42[[deprecated("Use pw::system::StartAndClobberTheStack()")]] [[noreturn]] void
44
45namespace system {
46
71[[noreturn]] void StartAndClobberTheStack(
72 channel::ByteReaderWriter& io_channel);
73
76class AsyncCore {
77 public:
80
83
85 rpc::Server& rpc_server() { return rpc_server_; }
86
92 [[nodiscard]] bool RunOnce(Function<void()>&& function);
93
94 private:
95 friend AsyncCore& pw::System();
97
98 explicit _PW_RPC_CONSTEXPR AsyncCore()
99 : rpc_channels_{}, rpc_server_(rpc_channels_) {}
100
101 void Init(channel::ByteReaderWriter& io_channel);
102
103 static async2::Poll<> InitTask(async2::Context&);
104
105 rpc::Channel rpc_channels_[1];
106 rpc::Server rpc_server_;
107};
108
109} // namespace system
110
112 _PW_RPC_CONSTINIT static system::AsyncCore system_core;
113 return system_core;
114}
115
116} // 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:232
Definition: server.h:36
Definition: system.h:76
fit::function_impl< function_internal::config::kInlineCallableSize, !function_internal::config::kEnableDynamicAllocation, FunctionType, PW_FUNCTION_DEFAULT_ALLOCATOR_TYPE > Function
Definition: function.h:73
void StartAndClobberTheStack(channel::ByteReaderWriter &io_channel)
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:85
async2::Dispatcher & dispatcher()
Returns the system pw::async2::Dispatcher instance.
bool RunOnce(Function< void()> &&function)
system::AsyncCore & System()
Definition: system.h:111
The Pigweed namespace.
Definition: alignment.h:27