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_async2/dispatcher.h"
20#include "pw_channel/channel.h"
21#include "pw_function/function.h"
22#include "pw_rpc/server.h"
23
24namespace pw {
25
27
29namespace system {
30
31class AsyncCore; // Forward declaration for function declaration.
32
33} // namespace system
34
39
43[[deprecated("Use pw::system::StartAndClobberTheStack()")]] [[noreturn]] void
45
46namespace system {
47
72[[noreturn]] void StartAndClobberTheStack(
73 channel::ByteReaderWriter& io_channel);
74
77class AsyncCore {
78 public:
81
84
86 rpc::Server& rpc_server() { return rpc_server_; }
87
93 [[nodiscard]] bool RunOnce(Function<void()>&& function);
94
95 private:
96 friend AsyncCore& pw::System();
98
99 explicit _PW_RPC_CONSTEXPR AsyncCore()
100 : rpc_channels_{}, rpc_server_(rpc_channels_) {}
101
102 void Init(channel::ByteReaderWriter& io_channel);
103
104 static async2::Poll<> InitTask(async2::Context&);
105
106 rpc::Channel rpc_channels_[1];
107 rpc::Server rpc_server_;
108};
109
110} // namespace system
111
113 _PW_RPC_CONSTINIT static system::AsyncCore system_core;
114 return system_core;
115}
116
117} // namespace pw
Definition: allocator.h:36
Definition: context.h:54
Definition: dispatcher.h:53
Definition: poll.h:60
Definition: channel.h:59
Definition: channel.h:232
Definition: server.h:36
Definition: system.h:77
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:86
async2::Dispatcher & dispatcher()
Returns the system pw::async2::Dispatcher instance.
bool RunOnce(Function< void()> &&function)
system::AsyncCore & System()
Definition: system.h:112
The Pigweed namespace.
Definition: alignment.h:27