### Broker Initialization and Launching (C++) Source: https://www.actor-framework.org/static/doxygen/0.19.0/classcaf_1_1io_1_1broker-members Methods related to the lifecycle management of IO brokers. 'init_broker' performs initial setup for abstract brokers, while 'launch' starts the execution of an abstract broker, optionally in a lazy or hidden mode. 'initialize' is an override for broker-specific setup. ```C++ // Initializes the abstract broker void init_broker(); // Launches the abstract broker execution void launch(execution_unit *eu, bool lazy, bool hide); // Override for broker initialization void initialize(); ``` -------------------------------- ### WebSocket Server Start Source: https://www.actor-framework.org/static/doxygen/0.19.3/classcaf_1_1net_1_1web__socket_1_1server__factory Starts a WebSocket server that accepts incoming connections. ```APIDOC ## POST /websites/actor-framework/start ### Description Starts a server that accepts incoming connections with the WebSocket protocol. ### Method POST ### Endpoint /websites/actor-framework/start ### Parameters #### Query Parameters - **on_start** (OnStart) - Required - Callback function to execute after the server starts. ### Request Example ```json { "on_start": "your_start_callback_function" } ``` ### Response #### Success Response (200) - **disposable** (expected< disposable >) - An object that can be used to stop the server. #### Response Example ```json { "disposable": "" } ``` ``` -------------------------------- ### Scheduler Coordinator Start Method Source: https://www.actor-framework.org/static/doxygen/0.19.1/classcaf_1_1scheduler_1_1coordinator-members Documentation for the 'start()' override method in caf::scheduler::coordinator. ```APIDOC ## Method: start() ### Description Starts the scheduler coordinator. This method overrides the base class virtual function. ### Method `void start() override` ### Defined In `caf::scheduler::coordinator< Policy >` ### Access Protected ### Example ```cpp // This method is typically called internally by the framework. // Direct calls might not be intended for external use. ``` ``` -------------------------------- ### CAF Main Setup (C++) Source: https://www.actor-framework.org/static/doxygen/0.19.0/dining_philosophers_8cpp-example Initializes the CAF actor system and sets up the Dining Philosophers simulation. It creates five chopstick actors and five philosopher actors, assigning them specific chopsticks. This function serves as the entry point for the CAF application. ```cpp void caf_main(actor_system& system) { scoped_actor self{system}; // create five chopsticks aout(self) << "chopstick ids are:"; std::vector chopsticks; for (size_t i = 0; i < 5; ++i) { chopsticks.push_back(self->spawn(available_chopstick)); aout(self) << " " << chopsticks.back()->id(); } aout(self) << endl; // spawn five philosophers std::vector names{"Plato", "Hume", "Kant", "Nietzsche", "Descartes"}; for (size_t i = 0; i < 5) self->spawn(names[i], chopsticks[i], chopsticks[(i + 1) % 5]); } CAF_MAIN(id_block::dining_philosophers) caf::actor_config Stores spawn-time flags and groups. **Definition:** actor_config.hpp:19 caf::actor_system Actor environment including scheduler, registry, and optional components such as a middleman. **Definition:** actor_system.hpp:90 caf::behavior Describes the behavior of an actor, i.e., provides a message handler and an optional timeout. **Definition:** behavior.hpp:25 caf::event_based_actor A cooperatively scheduled, event-based actor implementation. **Definition:** event_based_actor.hpp:40 caf::intrusive_ptr< actor_control_block > caf::result Wraps the result of a message handler to represent either a value (wrapped into a message),... **Definition:** fwd.hpp:61 caf::scoped_actor A scoped handle to a blocking actor. **Definition:** scoped_actor.hpp:18 caf::typed_actor Identifies a statically typed actor. **Definition:** typed_actor.hpp:32 caf Root namespace of libcaf. **Definition:** abstract_actor.hpp:29 caf::aout CAF_CORE_EXPORT actor_ostream aout(local_actor *self) Convenience factory function for creating an actor output stream. ``` -------------------------------- ### Start Profiled Coordinator Threads - C++ Source: https://www.actor-framework.org/static/doxygen/0.19.0/classcaf_1_1scheduler_1_1profiled__coordinator The `start` method is responsible for initiating any background threads required by the profiled coordinator module. This method overrides the `start` method from the `coordinator` base class. ```cpp template> void caf::scheduler::profiled_coordinator< Policy >::start() ``` -------------------------------- ### Actor Lifecycle and Setup Source: https://www.actor-framework.org/static/doxygen/1.0.0/classcaf_1_1local__actor Functions related to the setup, cleanup, and launching of actors. ```APIDOC ## Actor Lifecycle and Setup ### Description Functions for initializing, cleaning up, and launching actors within the framework. ### Methods - **local_actor(actor_config &cfg)** - Description: Initializes a local actor with the provided configuration. - Method: Constructor - Endpoint: N/A - **on_cleanup(const error &)** - Description: Called from `cleanup` to perform extra cleanup actions for this actor. Can be overridden. - Method: Virtual Override - Endpoint: N/A - **setup_metrics()** - Description: Sets up metrics for the actor. - Method: Member Function - Endpoint: N/A - **launch(scheduler *sched, bool lazy, bool hide)** - Description: Launches the actor with the given scheduler and options. - Method: Pure Virtual Function - Endpoint: N/A - **on_exit()** - Description: Can be overridden to perform cleanup code after an actor finished execution. - Method: Virtual Override - Endpoint: N/A ``` -------------------------------- ### Hello World Example in CAF 0.15 (C++) Source: https://www.actor-framework.org/blog/2016-05/a-glimpse-at-the-future-of-caf Demonstrates the 'Hello World' actor example using CAF version 0.15. It showcases the new `actor_system` and simplified actor management. This example requires the CAF library. ```cpp behavior mirror(event_based_actor* self) { // return the (initial) actor behavior return { // a handler for messages containing a single string // that replies with a string [=](const string& what) -> string { // prints "Hello World!" via aout (thread-safe cout wrapper) aout(self) << what << endl; // reply "!dlroW olleH" return string(what.rbegin(), what.rend()); } }; } void hello_world(event_based_actor* self, const actor& buddy) { // send "Hello World!" to our buddy ... self->request(buddy, std::chrono::seconds(10), "Hello World!").then( // ... wait up to 10s for a response ... [=](const string& what) { // ... and print it aout(self) << what << endl; } ); } int main() { // our CAF environment actor_system system; // create a new actor that calls 'mirror()' auto mirror_actor = system.spawn(mirror); // create another actor that calls 'hello_world(mirror_actor)'; system.spawn(hello_world, mirror_actor); // system will wait until both actors are destroyed before leaving main } ``` -------------------------------- ### Hello World Example in C++ Source: https://www.actor-framework.org/static/doxygen/0.19.3/index A basic 'Hello World' example demonstrating the core concepts of the C++ Actor Framework. It shows how to define actor behaviors, spawn actors, send messages, and handle responses. This example uses `actor_system` for managing actors and `event_based_actor` for defining actor logic. ```C++ #include "caf/actor_ostream.hpp" #include "caf/actor_system.hpp" #include "caf/caf_main.hpp" #include "caf/event_based_actor.hpp" #include #include using namespace caf; behavior mirror(event_based_actor* self) { // return the (initial) actor behavior return { // a handler for messages containing a single string // that replies with a string [=](const std::string& what) -> std::string { // prints "Hello World!" via aout (thread-safe cout wrapper) aout(self) << what << std::endl; // reply "!dlroW olleH" return std::string{what.rbegin(), what.rend()}; }, }; } void hello_world(event_based_actor* self, const actor& buddy) { // send "Hello World!" to our buddy ... self->request(buddy, std::chrono::seconds(10), "Hello World!") .then( // ... wait up to 10s for a response ... [=](const std::string& what) { // ... and print it aout(self) << what << std::endl; }); } void caf_main(actor_system& sys) { // create a new actor that calls 'mirror()' auto mirror_actor = sys.spawn(mirror); // create another actor that calls 'hello_world(mirror_actor)'; sys.spawn(hello_world, mirror_actor); // the system will wait until both actors are done before exiting the program } // creates a main function for us that calls our caf_main CAF_MAIN() ``` -------------------------------- ### Starting an HTTP Server in C++ Source: https://www.actor-framework.org/static/doxygen/0.19.3/classcaf_1_1net_1_1http_1_1server__factory Illustrates how to start an HTTP server in C++ using the CAF framework. It covers starting a server that only serves pre-defined routes and a server that can also handle requests without a fixed route, making it available to an observer. The `start` function returns an `expected`. ```cpp // Start a server that only serves fixed routes // expected disp = server.start(); // Start a server that makes HTTP requests without a fixed route available to an observer // template // expected start(OnStart on_start); // server.start([](auto& server_instance) { /* callback actions */ }); ``` -------------------------------- ### Module Lifecycle: Start and Init in Abstract Coordinator Source: https://www.actor-framework.org/static/doxygen/0.19.1/classcaf_1_1scheduler_1_1abstract__coordinator Shows the overridden 'start()' and 'init()' functions. 'start()' initializes any background threads, and 'init()' allows modification of the actor system's configuration during startup. These are essential for module lifecycle management. ```cpp void | start () override | Starts any background threads needed by the module. void | init (actor_system_config &cfg) override | Allows the module to change the configuration of the actor system during startup. ``` -------------------------------- ### start Source: https://www.actor-framework.org/static/doxygen/0.19.1/classcaf_1_1io_1_1network_1_1stream__impl Starts reading data from the socket and forwards incoming data to the provided stream manager. ```APIDOC ## start ### Description Initiates the process of reading data from the associated socket. Incoming data will be forwarded to the specified `stream_manager`. ### Method `void` ### Endpoint N/A (Member Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "example": "stream_manager *mgr" } ``` ### Response #### Success Response (200) None (This is a void function). #### Response Example N/A ``` -------------------------------- ### start() Source: https://www.actor-framework.org/static/doxygen/0.19.0/classcaf_1_1io_1_1middleman Starts any background threads needed by the IO middleman module. ```APIDOC ## POST /websites/actor-framework/start ### Description Starts any background threads needed by the module. Implements caf::actor_system::module. ### Method POST ### Endpoint /websites/actor-framework/start ### Response #### Success Response (200) - **status** (string) - Indicates that the middleman has started. #### Response Example ```json { "status": "started" } ``` ``` -------------------------------- ### Hello World Example in CAF 0.14 (C++) Source: https://www.actor-framework.org/blog/2016-05/a-glimpse-at-the-future-of-caf Illustrates the 'Hello World' actor example using CAF version 0.14. This version uses a singleton-based design and requires explicit calls to `await_all_actors_done()` and `shutdown()`. This example requires the CAF library. ```cpp behavior mirror(event_based_actor* self) { // return the (initial) actor behavior return { // a handler for messages containing a single string // that replies with a string [=](const string& what) -> string { // prints "Hello World!" via aout (thread-safe cout wrapper) aout(self) << what << endl; // terminates this actor ('become' otherwise loops forever) self->quit(); // reply "!dlroW olleH" return string(what.rbegin(), what.rend()); } }; } void hello_world(event_based_actor* self, const actor& buddy) { // send "Hello World!" to our buddy ... self->sync_send(buddy, "Hello World!").then( // ... wait for a response ... [=](const string& what) { // ... and print it aout(self) << what << endl; } ); } int main() { // create a new actor that calls 'mirror()' auto mirror_actor = spawn(mirror); // create another actor that calls 'hello_world(mirror_actor)'; spawn(hello_world, mirror_actor); // wait until all other actors we have spawned are done await_all_actors_done(); // run cleanup code before exiting main shutdown(); } ``` -------------------------------- ### Profiled Coordinator Start Source: https://www.actor-framework.org/static/doxygen/0.19.3/classcaf_1_1scheduler_1_1profiled__coordinator Starts any necessary background threads for the profiled coordinator. This is an override from the base coordinator class. ```APIDOC ## void start() ### Description Starts any background threads needed by the module. Reimplemented from caf::scheduler::coordinator< Policy >. ### Method `void` ### Endpoint N/A (Class Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ``` // Example usage after initialization ``` ### Response #### Success Response (N/A) This method does not return a value. #### Response Example N/A ``` -------------------------------- ### Hello World Example in C++ Actor Framework Source: https://www.actor-framework.org/static/doxygen/0.19.1/index Demonstrates a basic 'Hello World' example using the C++ Actor Framework. It includes setting up an actor system, defining actor behaviors, and spawning actors to communicate. This example requires the CAF library. It takes a string as input and returns its reversed version, illustrating message handling and replies. ```C++ #include #include #include "caf/actor_ostream.hpp" #include "caf/actor_system.hpp" #include "caf/caf_main.hpp" #include "caf/event_based_actor.hpp" using namespace caf; behavior mirror(event_based_actor* self) { // return the (initial) actor behavior return { // a handler for messages containing a single string // that replies with a string [=](const std::string& what) -> std::string { // prints "Hello World!" via aout (thread-safe cout wrapper) aout(self) << what << std::endl; // reply "!dlroW olleH" return std::string{what.rbegin(), what.rend()}; }, }; } void hello_world(event_based_actor* self, const actor& buddy) { // send "Hello World!" to our buddy ... self->request(buddy, std::chrono::seconds(10), "Hello World!") .then( // ... wait up to 10s for a response ... [=](const std::string& what) { // ... and print it aout(self) << what << std::endl; }); } void caf_main(actor_system& sys) { // create a new actor that calls 'mirror()' auto mirror_actor = sys.spawn(mirror); // create another actor that calls 'hello_world(mirror_actor)'; sys.spawn(hello_world, mirror_actor); // the system will wait until both actors are done before exiting the program } // creates a main function for us that calls our caf_main CAF_MAIN() ``` -------------------------------- ### Class Member Documentation Source: https://www.actor-framework.org/static/doxygen/0.19.3/functions_g This section provides details on documented class members, categorized by their starting letter. It includes functions like 'gauge_family', 'get', and 'graceful_shutdown'. ```APIDOC ## Class Members Documentation ### Description This section lists documented class members, with a focus on members starting with the letter 'g'. It includes functions related to metrics, retrieval of actor information, and network operations. ### Method N/A (Documentation Reference) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response #### Success Response (200) - **Member Name** (string) - The name of the class member. - **Class** (string) - The class to which the member belongs. #### Response Example ```json { "member_name": "gauge_family", "class": "caf::telemetry::metric_registry" } ``` ```json { "member_name": "get", "class": "caf::actor_control_block, caf::actor_registry, ..." } ``` ```json { "member_name": "graceful_shutdown", "class": "caf::io::network::acceptor, caf::io::network::event_handler, ..." } ``` ``` -------------------------------- ### Initialize WebSocket Framing Layer (C++) Source: https://www.actor-framework.org/static/doxygen/0.19.1/classcaf_1_1net_1_1web__socket_1_1framing The `start()` method initializes the upper layer of the WebSocket framing. It requires a pointer to the lower layer, which must remain valid for the lifetime of the upper layer. ```cpp void caf::net::web_socket::framing::start( octet_stream::lower_layer* down_ ) override; // Implements caf::net::octet_stream::upper_layer. ``` -------------------------------- ### start() - Initialize Upper Layer Source: https://www.actor-framework.org/static/doxygen/0.19.3/classcaf_1_1net_1_1http_1_1router Initializes the upper layer. This method is called during the setup of the HTTP communication. ```APIDOC ## POST /websites/actor-framework/start ### Description Initializes the upper layer. This method is called during the setup of the HTTP communication. ### Method POST ### Endpoint /websites/actor-framework/start ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **lower_layer** (lower_layer*) - Required - A pointer to the lower layer that remains valid for the lifetime of the upper layer. ### Request Example ```json { "lower_layer": "0x..." } ``` ### Response #### Success Response (200) - **status** (error) - Indicates the success or failure of the initialization. #### Response Example ```json { "status": "success" } ``` ``` -------------------------------- ### Ccaf::net::dsl::server_config Source: https://www.actor-framework.org/static/doxygen/0.19.0/hierarchy Wraps configuration parameters for starting servers. ```APIDOC ## Ccaf::net::dsl::server_config ### Description Wraps configuration parameters for starting clients. ### Method N/A (Class Definition) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Get This Actor Handle in BASP Source: https://www.actor-framework.org/static/doxygen/0.18.7/classcaf_1_1io_1_1basp__broker Returns a handle to the current actor instance (the callee). This allows the actor to refer to itself, for example, when sending messages. ```cpp strong_actor_ptr this_actor () override | Returns a handle to the callee actor. ``` -------------------------------- ### Get Internal Actor for Runtime Configuration Source: https://www.actor-framework.org/static/doxygen/0.19.1/classcaf_1_1actor__system Retrieves a constant reference to the internal actor responsible for managing and storing the runtime configuration of the actor system. This is crucial for system setup and modification. ```cpp const strong_actor_ptr & config_serv () const; ``` -------------------------------- ### start() - Web Socket Server Source: https://www.actor-framework.org/static/doxygen/0.19.3/classcaf_1_1net_1_1web__socket_1_1server Initializes the upper layer of the web socket server. ```APIDOC ## error start(octet_stream::lower_layer *down) ### Description Initializes the upper layer of the web socket server. ### Method POST ### Endpoint /websites/actor-framework/start ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **lower_layer_ptr** (pointer) - Required - A pointer to the lower layer that remains valid for the lifetime of the upper layer. ### Request Example ```json { "lower_layer_ptr": "0x7ffc12345678" } ``` ### Response #### Success Response (200) - **error_code** (integer) - The error code indicating the result of the initialization. 0 for success. #### Response Example ```json { "error_code": 0 } ``` ``` -------------------------------- ### Generic Configuration Class (C++) Source: https://www.actor-framework.org/static/doxygen/0.19.1/namespacecaf_1_1net_1_1dsl Wraps configuration for base parameters before determining if a client or server is being started. This class is useful for initial setup common to both. ```cpp class generic_config { // ... members for generic configuration }; ``` -------------------------------- ### Accessing caf::save_inspector Members in C++ Source: https://www.actor-framework.org/static/doxygen/0.19.1/classcaf_1_1save__inspector-members This snippet demonstrates how to interact with members of the `caf::save_inspector` class. It includes examples of setting and getting errors, as well as defining fields for serialization or inspection. ```cpp // Example of setting an error caf::save_inspector inspector; inspector.set_error(caf::make_error(caf::sec::runtime_error, "A custom error occurred.")); // Example of getting the current error auto err = inspector.get_error(); // Example of defining a field with a name and a reference int my_value; inspector.field("my_field", my_value); // Example of defining a field with a name, getter, and setter inspector.field("another_field", []{ return 42; }, [](int val){ /* handle set */ }); // Example of defining a field with presence check, getter, and setter inspector.field("optional_field", []{ return true; }, []{ return "optional_value"; }, [](std::string val){ /* handle set */ }); ``` -------------------------------- ### Ccaf::net::dsl::client_config Source: https://www.actor-framework.org/static/doxygen/0.19.0/hierarchy Wraps configuration parameters for starting clients. ```APIDOC ## Ccaf::net::dsl::client_config ### Description Wraps configuration parameters for starting clients. ### Method N/A (Class Definition) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Field Type Suffix for JSON Writer Source: https://www.actor-framework.org/static/doxygen/0.19.1/classcaf_1_1json__writer Returns a suffix used for generating type annotation fields, particularly for variant types in JSON. For example, a field named 'foo' might get an annotation field like '@foo${field_type_suffix}'. ```c++ std::string_view caf::json_writer::field_type_suffix() const noexcept ``` -------------------------------- ### Get JSON Field Type Suffix (C++) Source: https://www.actor-framework.org/static/doxygen/0.19.0/classcaf_1_1json__builder The `field_type_suffix` function returns a string view representing the suffix used for generating type annotation fields for variant fields in JSON. For example, it might append `${field_type_suffix}` to a field name. ```c++ std::string_view caf::json_builder::field_type_suffix() const noexcept ``` -------------------------------- ### HTTP Server Factory and Routing in C++ Source: https://www.actor-framework.org/static/doxygen/0.19.3/classcaf_1_1net_1_1http_1_1server__factory Demonstrates how to create and configure an HTTP server using the CAF framework. It shows how to define routes with different HTTP methods and actions, and how to start the server. This factory pattern allows for a fluent DSL for server setup. ```cpp #include #include // Assuming server_config and server_factory are defined elsewhere // using namespace caf; // using namespace caf::net; // Example usage: // auto server = http::server_factory_base(); // server.route("/", [](auto req) { return make_message(http::status::ok, "Hello, World!"); }); // server.route("/api", http::method::get, [](auto req) { /* handle GET request */ }); // server.start(); ``` -------------------------------- ### WebSocket Framing: start() Source: https://www.actor-framework.org/static/doxygen/0.19.3/classcaf_1_1net_1_1web__socket_1_1framing Initializes the upper layer of the web socket framing. ```APIDOC ## POST /websites/actor-framework/framing/start ### Description Initializes the upper layer of the web socket framing. ### Method POST ### Endpoint `/websites/actor-framework/framing/start` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **down** (octet_stream::lower_layer *) - Required - A pointer to the lower layer that remains valid for the lifetime of the upper layer. ### Request Example ```json { "down": "pointer_to_lower_layer" } ``` ### Response #### Success Response (200) * **error** (error) - An error code indicating the result of the initialization. #### Response Example ```json { "error": "error_code_or_default" } ``` ``` -------------------------------- ### Ccaf::net::dsl::has_context< Base, Subtype > Source: https://www.actor-framework.org/static/doxygen/0.19.0/hierarchy DSL entry point for creating a server. ```APIDOC ## Ccaf::net::dsl::has_context< Base, Subtype > ### Description DSL entry point for creating a server. ### Method N/A (Class Definition) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Get Field Type Suffix - C++ Source: https://www.actor-framework.org/static/doxygen/0.18.7/classcaf_1_1json__writer Retrieves the suffix used for generating type annotation fields for variant fields. CAF uses this suffix to append to field names for type information, for example, '@foo${field_type_suffix}' for a variant field named 'foo'. This method is `noexcept`. ```cpp string_view caf::json_writer::field_type_suffix() const noexcept ``` -------------------------------- ### Get or Deduction Guide for caf::config_value Source: https://www.actor-framework.org/static/doxygen/0.19.0/structcaf_1_1get__or__deduction__guide Provides a customization point for mapping default value types to deduced types within the caf::config_value structure. It ensures correct type deduction, for instance, returning a string instead of a string_view. User-defined overloads should not specialize this for types in the 'std' or 'caf' namespaces. ```cpp #include template struct caf::get_or_deduction_guide< T > ``` ```cpp template static decltype(auto) convert(V &&x) ``` -------------------------------- ### start() Source: https://www.actor-framework.org/static/doxygen/0.19.0/classcaf_1_1net_1_1web__socket_1_1client Initializes the upper layer of the web socket client, requiring a pointer to the lower layer. ```APIDOC ## POST /websites/actor-framework/start ### Description Initializes the upper layer of the web socket client. Implements `caf::net::octet_stream::upper_layer`. ### Method POST ### Endpoint /websites/actor-framework/start ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **_down_** (octet_stream::lower_layer*) - Required - A pointer to the lower layer that remains valid for the lifetime of the upper layer. ### Request Example ```json { "_down_": "" } ``` ### Response #### Success Response (200) - **status** (error) - Indicates the result of the initialization. Success is typically represented by an error code of 0. #### Response Example ```json { "status": 0 } ``` ``` -------------------------------- ### Get Last N Elements of a Type List in C++ Source: https://www.actor-framework.org/static/doxygen/0.18.7/structcaf_1_1detail_1_1tl__right This C++ struct, `tl_right`, creates a new type list containing the last N elements from an existing list. It relies on template metaprogramming and the `tl_slice_t` and `tl_size` types from the CAF library. The `first_idx` static member calculates the starting index for slicing. ```cpp #include template::value> struct caf::detail::tl_right< List, NewSize, OldSize > { using type = tl_slice_t< List, first_idx, OldSize >; static constexpr size_t first_idx = OldSize > NewSize ? OldSize - NewSize : 0; }; ``` -------------------------------- ### CAF Actor System Module Interface (C++) Source: https://www.actor-framework.org/static/doxygen/0.19.0/classcaf_1_1actor__system_1_1module-members Defines the interface for a module within the CAF actor system. It includes pure virtual functions for initialization, starting, stopping, and obtaining a subtype pointer, along with methods to get the module's ID and name. This interface is fundamental for extending the actor system with custom modules. ```cpp namespace caf { namespace actor_system { class module { public: using id_t = uint16_t; virtual ~module() = default; virtual id_t id() const = 0; virtual char const* name() const noexcept = 0; virtual void init(actor_system_config& cfg) = 0; virtual void start() = 0; virtual void stop() = 0; virtual std::unique_ptr subtype_ptr() = 0; // Enum values for common module identifiers enum { middleman, scheduler, network_manager, openssl_manager, num_ids }; }; } // namespace actor_system } // namespace caf ``` -------------------------------- ### Metrics Setup Source: https://www.actor-framework.org/static/doxygen/1.0.0/classcaf_1_1abstract__blocking__actor Function for setting up actor metrics. ```APIDOC ## Metrics Setup ### Description Initializes metrics collection for the actor. ### Method - **setup_metrics** () - Description: Sets up metrics for the actor. ``` -------------------------------- ### Middleman Start API Source: https://www.actor-framework.org/static/doxygen/0.19.3/classcaf_1_1net_1_1middleman Starts any background threads required by the middleman module. ```APIDOC ## POST /websites/actor-framework/middleman/start ### Description Starts any background threads needed by the module. ### Method POST ### Endpoint /websites/actor-framework/middleman/start ### Parameters None ### Request Example None ### Response #### Success Response (200) - **status** (string) - Indicates that the middleman has started. #### Response Example ```json { "status": "started" } ``` ``` -------------------------------- ### Initialize HTTP Router - C++ Source: https://www.actor-framework.org/static/doxygen/0.19.0/classcaf_1_1net_1_1http_1_1router The start function initializes the HTTP router's upper layer. It requires a pointer to the lower layer, which is guaranteed to remain valid throughout the upper layer's lifetime. Implements caf::net::http::upper_layer. ```cpp error caf::net::http::router::start(lower_layer* _down_) ``` -------------------------------- ### Starting and Activating an Acceptor in C++ Source: https://www.actor-framework.org/static/doxygen/0.19.3/classcaf_1_1io_1_1network_1_1acceptor Demonstrates how to start and activate an acceptor using a provided 'acceptor_manager'. The 'start' function initializes the acceptor, and 'activate' prepares it for operation. ```cpp #include // Starts this acceptor, forwarding all incoming connections to `manager`. void start(acceptor_manager *mgr); // Activates the acceptor. void activate(acceptor_manager *mgr); ``` -------------------------------- ### Server Configuration API Source: https://www.actor-framework.org/static/doxygen/1.0.0/classcaf_1_1net_1_1dsl_1_1server__config This section details the configuration parameters for starting clients using the server configuration. ```APIDOC ## Detailed Description Wraps configuration parameters for starting clients. * * * The documentation for this class was generated from the following file: * libcaf_net/caf/net/dsl/server_config.hpp ``` ```APIDOC ## Classes --- class | lazy | Configuration for a server that creates the socket on demand. More... class | socket | Configuration for a server that uses a user-provided socket. More... ``` ```APIDOC ## Public Types --- using | **lazy_t** = server_config_tag using | **socket_t** = server_config_tag using | **fail_t** = server_config_tag ``` ```APIDOC ## Static Public Attributes --- static constexpr auto | **lazy_v** = lazy_t{} static constexpr auto | **socket_v** = socket_t{} static constexpr auto | **fail_v** = fail_t{} ``` -------------------------------- ### Generic Configuration and DSL Entries Source: https://www.actor-framework.org/static/doxygen/0.19.1/namespaces Generic configuration wrappers and DSL entry points for creating clients and servers. ```APIDOC ## Generic Configuration and DSL Entries ### Description Utilities for general configuration and specific DSL entry points for network connection setup. ### Components - **Cgeneric_config** - Description: Wraps configuration of some base parameters before we know whether the user is starting a client or a server. - **Clazy** - Description: Configuration for a client that creates the socket on demand. - **Cgeneric_config_tag** - Description: Meta programming utility. - **Cget_name** - Description: Meta programming utility for accessing the name of a type. - **Chas_accept** - Description: DSL entry point for creating a server. - **Chas_connect** - Description: DSL entry point for creating a client. - **Chas_context** - Description: DSL entry point for creating a server. - **Chas_ctx** - Description: Configuration for a client that uses a user-provided socket. - **Chas_uri_connect** - Description: DSL entry point for creating a client from an URI. - **Cserver_address** - Description: Simple type for storing host and port information for reaching a server. ``` -------------------------------- ### Start Actor System Module (C++) Source: https://www.actor-framework.org/static/doxygen/1.0.0/classcaf_1_1actor__system_1_1networking__module-members Declares the pure virtual function `start` within the `caf::actor_system_module` class. This function is responsible for starting the module's operations. ```c++ start() = 0; ``` -------------------------------- ### Minimal Actor Framework Application Setup (C++) Source: https://www.actor-framework.org/blog/2015-08/testing-brokers This C++ code snippet demonstrates a minimal application setup using the Actor Framework's brokers. It includes functions to spawn an IO server on a specific port, wait for all actors to complete, and shut down the system. ```C++ int main() { spawn_io_server(server, 8080); await_all_actors_done(); shutdown(); } ``` -------------------------------- ### accept_handler::start Source: https://www.actor-framework.org/static/doxygen/0.19.1/classcaf_1_1detail_1_1accept__handler Starts processing on this layer. Implements caf::net::socket_event_layer. ```APIDOC ## error start(net::socket_manager * _owner_) ### Description Starts processing on this layer. Implements caf::net::socket_event_layer. ### Method error ### Endpoint N/A (Method within a class) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "_owner_": {"type": "net::socket_manager *"} // Placeholder for socket manager pointer } ``` ### Response #### Success Response (200) - **error_code** (error) - An error code indicating success or failure. #### Response Example ```json { "error_code": 0 // Example success error code } ``` ``` -------------------------------- ### C++ Actor Framework: Deduction Guide for Configuration Values Source: https://www.actor-framework.org/static/doxygen/0.18.7/structcaf_1_1get__or__deduction__guide This C++ code defines a customization point for configuring automatic mappings from default value types to deduced types within the C++ Actor Framework. It is used to ensure correct type handling, for example, returning a string instead of a string_view. User-defined overloads must adhere to specific namespace restrictions. ```cpp #include template struct caf::get_or_deduction_guide< T > { using value_type = T; template static decltype(auto) convert(V &&x); }; /* Customization point for configuring automatic mappings from default value types to deduced types. For example, `get_or(value, "foo"sv)` must return a `string` rather than a `string_view`. However, user-defined overloads _must not_ specialize this class for any type from the namespaces `std` or `caf`. */ ``` -------------------------------- ### HTTP Configuration DSL Entry Points (C++) Source: https://www.actor-framework.org/static/doxygen/0.19.0/namespacecaf_1_1net_1_1http Defines the `with` functions that serve as entry points for the HTTP configuration DSL. These functions are overloaded to accept either an actor system or a multiplexer. ```C++ with_t | **with** (actor_system &sys) with_t | **with** (multiplexer *mpx) ``` -------------------------------- ### Get or Modify caf::message Elements Source: https://www.actor-framework.org/static/doxygen/1.0.0/classcaf_1_1message-members Functions to access or modify elements within a `caf::message` by index. Provides methods to get elements as a specific type and to get mutable references. ```cpp get_as(size_t index) const noexcept; get_mutable_as(size_t index) noexcept; ``` -------------------------------- ### C++ Actor Framework 'Hello World' Example Source: https://www.actor-framework.org/static/doxygen/1.0.0/index Demonstrates a basic 'Hello World' application using the C++ Actor Framework (CAF). It defines an actor behavior ('mirror') that echoes a string in reverse and a function ('hello_world') to send a message and receive a reply. The main function sets up the actor system and spawns these actors. Dependencies include CAF headers like 'actor_ostream.hpp', 'actor_system.hpp', 'caf_main.hpp', and 'event_based_actor.hpp'. ```C++ #include "caf/actor_ostream.hpp" #include "caf/actor_system.hpp" #include "caf/caf_main.hpp" #include "caf/event_based_actor.hpp" #include using namespace caf; using namespace std::literals; behavior mirror(event_based_actor* self) { // return the (initial) actor behavior return { // a handler for messages containing a single string // that replies with a string [self](const std::string& what) -> std::string { // prints "Hello World!" (thread-safe) self->println("{}", what); // reply "!dlroW olleH" return std::string{what.rbegin(), what.rend()}; }, }; } void hello_world(event_based_actor* self, const actor& buddy) { // send "Hello World!" to our buddy ... self->mail("Hello World!") .request(buddy, 10s) .then( // ... wait up to 10s for a response ... [self](const std::string& what) { // ... and print it self->println("{}", what); }); } void caf_main(actor_system& sys) { // create a new actor that calls 'mirror()' auto mirror_actor = sys.spawn(mirror); // create another actor that calls 'hello_world(mirror_actor)'; sys.spawn(hello_world, mirror_actor); // the system will wait until both actors are done before exiting the program } // creates a main function for us that calls our caf_main CAF_MAIN() ``` -------------------------------- ### Initialize Profiled Coordinator Configuration - C++ Source: https://www.actor-framework.org/static/doxygen/0.19.0/classcaf_1_1scheduler_1_1profiled__coordinator The `init` method allows modification of the actor system's configuration during the startup phase. It is an override from the `abstract_coordinator` class and takes an `actor_system_config` object as input. ```cpp template> void caf::scheduler::profiled_coordinator< Policy >::init(actor_system_config & cfg) ``` -------------------------------- ### Configuration and Customization Source: https://www.actor-framework.org/static/doxygen/0.19.1/namespaces Utilities for configuration, deduction guides, and customization points. ```APIDOC ## Configuration and Customization ### Description This section covers utilities and customization points for configuring actor behavior, message handling, and type deductions. ### Endpoints #### `Cget_or_auto_deduce` ##### Description Configures `get_or` to use the `get_or_deduction_guide`. ##### Method N/A (Configuration Utility) ##### Endpoint N/A #### `Cget_or_deduction_guide` ##### Description Customization point for configuring automatic mappings from default value types to deduced types. ##### Method N/A (Customization Point) #### `Cis_error_code_enum` ##### Description Customization point for enabling conversion from an enum type to an error or `error_code`. ##### Method N/A (Customization Point) ##### Endpoint N/A #### `Cis_variant_wrapper` ##### Description Customization point for variant wrappers. ##### Method N/A (Customization Point) ##### Endpoint N/A #### `Cinspector_access` ##### Description Customization point for adding support for a custom type to the inspection API. ##### Method N/A (Customization Point) ##### Endpoint N/A #### `Cgroup_module` ##### Description Interface for user-defined multicast implementations. ##### Method N/A (Interface Definition) ##### Endpoint N/A ``` -------------------------------- ### Initialize Broker Source: https://www.actor-framework.org/static/doxygen/0.19.0/classcaf_1_1io_1_1basp__broker Initializes the broker, performing setup tasks necessary for its operation. This function is typically called once after the broker is created. ```C++ void initialize () override ``` -------------------------------- ### Profiled Coordinator Start API Source: https://www.actor-framework.org/static/doxygen/0.19.1/classcaf_1_1scheduler_1_1profiled__coordinator Starts any background threads needed by the module. This method is an override from caf::scheduler::coordinator. ```APIDOC ## void start() ### Description Starts any background threads needed by the module. Reimplemented from caf::scheduler::coordinator. ### Method `void` ### Endpoint `N/A` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None (void return type) #### Response Example None ``` -------------------------------- ### start Source: https://www.actor-framework.org/static/doxygen/0.19.1/classcaf_1_1detail_1_1ws__server__flow__bridge Starts the WebSocket server flow bridge by connecting it to the lower layer. ```APIDOC ## start ### Description Starts the WebSocket server flow bridge by connecting it to the lower layer. ### Method `start` ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### Server Configuration Source: https://www.actor-framework.org/static/doxygen/0.19.1/namespaces Configuration parameters for starting servers, including lazy and socket-based configurations. ```APIDOC ## Server Configuration ### Description Wrappers and utilities for configuring server setups, allowing for different socket and lazy initialization strategies. ### Components - **Cserver_config** - Description: Wraps configuration parameters for starting clients. - **Clazy** - Description: Configuration for a server that creates the socket on demand. - **Csocket** - Description: Configuration for a server that uses a user-provided socket. - **Cserver_config_tag** - Description: Meta programming utility. - **Cserver_factory_base** - Description: Base type for server factories for use with `can_accept`. ``` -------------------------------- ### Initialize Meta Objects Source: https://www.actor-framework.org/static/doxygen/0.19.0/namespacecaf Functions for initializing meta objects and loading modules. `exec_main_init_meta_objects_single` and `exec_main_init_meta_objects` handle meta object initialization, while `exec_main_load_module` loads a specific module. ```C++ template void | **exec_main_init_meta_objects_single** () ``` ```C++ template void | **exec_main_init_meta_objects** () ``` ```C++ template void | **exec_main_load_module** (actor_system_config &cfg) ``` -------------------------------- ### DSL Entry Point for Creating a Client (C++) Source: https://www.actor-framework.org/static/doxygen/0.19.1/namespacecaf_1_1net_1_1dsl Provides the Domain Specific Language (DSL) entry point for initiating client creation. It's used in conjunction with configuration objects to set up client connections. ```cpp class has_connect { // ... DSL methods for client connection }; ``` -------------------------------- ### Start HTTP Server - C++ Source: https://www.actor-framework.org/static/doxygen/0.19.1/classcaf_1_1net_1_1http_1_1server__factory Starts the HTTP server. This function can be used to start a server that serves only fixed routes or one that makes HTTP requests without a fixed route, responding to an observer. It returns an expected disposable object. ```cpp expected< disposable > start (OnStart on_start) expected< disposable > start () ``` -------------------------------- ### Initialization and System Management Source: https://www.actor-framework.org/static/doxygen/0.18.7/namespacecaf Functions for initializing the actor system and managing meta-objects. ```APIDOC ## Initialization and System Management ### Description Functions for initializing the actor system and managing meta-objects. ### `exec_main_init_meta_objects()` #### Description Initializes meta-objects for the main execution context. #### Method `void` ### `exec_main_load_module(actor_system_config &cfg)` #### Description Loads a module into the actor system configuration. #### Method `template` `void` ### `exec_main(F fun, int argc, char **argv)` #### Description Executes the main function of the actor system. #### Method `template` `int` ### `init_global_meta_objects_impl(std::integer_sequence< uint16_t, Is... >)` #### Description Implementation helper for initializing global meta objects. #### Method `template` `void` ### `init_global_meta_objects()` #### Description Initializes the global meta object table with all types in `ProjectIds`. #### Method `template` `void` ``` -------------------------------- ### Dining Philosophers Example in C++ using CAF Source: https://www.actor-framework.org/static/doxygen/0.19.0/dining_philosophers_8cpp-example An event-based implementation of the classical Dining Philosophers exercise using CAF's actor model. This example demonstrates actor communication, state management, and atom message passing. ```cpp #include #include #include #include #include #include #include #include "caf/all.hpp" CAF_BEGIN_TYPE_ID_BLOCK(dining_philosophers, first_custom_type_id) CAF_ADD_ATOM(dining_philosophers, take_atom) CAF_ADD_ATOM(dining_philosophers, taken_atom) CAF_ADD_ATOM(dining_philosophers, eat_atom) CAF_ADD_ATOM(dining_philosophers, think_atom) CAF_END_TYPE_ID_BLOCK(dining_philosophers) using std::cerr; using std::cout; using std::endl; using std::chrono::seconds; using namespace caf; namespace { // atoms for chopstick and philosopher interfaces // a chopstick using chopstick = typed_actor(take_atom), result(put_atom)>; chopstick::behavior_type taken_chopstick(chopstick::pointer, const strong_actor_ptr&); // either taken by a philosopher or available chopstick::behavior_type available_chopstick(chopstick::pointer self) { return { [=](take_atom) -> result { self->become(taken_chopstick(self, self->current_sender())); return {taken_atom_v, true}; }, [](put_atom) { cerr << "chopstick received unexpected 'put'" << endl; }, }; } chopstick::behavior_type taken_chopstick(chopstick::pointer self, const strong_actor_ptr& user) { return { [](take_atom) -> result { return {taken_atom_v, false}; }, [=](put_atom) { if (self->current_sender() == user) self->become(available_chopstick(self)); }, }; } // Based on: http://www.dalnefre.com/wp/2010/08/dining-philosophers-in-humus/ // // // +-------------+ {busy|taken} // +-------->| thinking |<------------------+ // | +-------------+ | // | | | // | | {eat} | // | | | // | V | // | +-------------+ {busy} +-------------+ // | | hungry |----------->| denied | // | +-------------+ +-------------+ // | | // | | {taken} // | | // | V // | +-------------+ // | | granted | // | +-------------+ // | | | // | {busy} | | {taken} // +-----------+ | // | V // | {think} +-------------+ // +---------| eating | // +-------------+ class philosopher : public event_based_actor { public: philosopher(actor_config& cfg, std::string n, chopstick l, chopstick r) : event_based_actor(cfg), name_(std::move(n)), left_(std::move(l)), right_(std::move(r)) { // we only accept one message per state and skip others in the meantime set_default_handler(skip); // a philosopher that receives {eat} stops thinking and becomes hungry thinking_.assign([=](eat_atom) { become(hungry_); send(left_, take_atom_v); send(right_, take_atom_v); }); } private: std::string name_; chopstick left_; chopstick right_; // state: thinking behavior_type thinking_; // state: hungry behavior_type hungry_; // state: eating behavior_type eating_; // state: denied behavior_type denied_; }; } ```