Branch data Line data Source code
1 : : // Copyright 2026 HPActor Contributors
2 : : //
3 : : // Licensed under the Apache License, Version 2.0 (the "License");
4 : : // you may not use this file except in compliance with the License.
5 : : // You may obtain a copy of the License at
6 : : //
7 : : // http://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,
11 : : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : : // See the License for the specific language governing permissions and
13 : : // limitations under the License.
14 : :
15 : : #pragma once
16 : :
17 : : #include <hpactor/actor/abstract_actor.hpp>
18 : : #include <hpactor/actor_context.hpp>
19 : :
20 : : namespace hpactor {
21 : :
22 : : // -----------------------------------------------------------------------------
23 : : // LocalActor - base class for actors with access to ActorContext
24 : : // -----------------------------------------------------------------------------
25 : : class LocalActor : public AbstractActor {
26 : : public:
27 : 736 : ActorContext* context() {
28 : 736 : return ctx_;
29 : : }
30 : : ActorSystem& home_system() {
31 : : return system();
32 : : }
33 : :
34 : : // Set the actor context (called by ActorSystem during spawn)
35 : 118 : void set_context(ActorContext* ctx) {
36 : 118 : ctx_ = ctx;
37 : 118 : }
38 : :
39 : : protected:
40 : : LocalActor(ActorContext* ctx, ActorSystem& sys);
41 : : LocalActor(ActorId id, ActorContext* ctx, ActorSystem& sys);
42 : :
43 : 10 : ActorContext* actor_context() override { return ctx_; }
44 : :
45 : : public:
46 : 4 : virtual void on_activate() {}
47 : 1 : virtual void on_deactivate() {}
48 : :
49 : : private:
50 : : ActorContext* ctx_ = nullptr;
51 : : };
52 : :
53 : : } // namespace hpactor
|