Skip to content

Commit 4edcac1

Browse files
Provide base classes in rosidl_pycommon (#887)
Signed-off-by: Michael Carlstrom <[email protected]>
1 parent 66b35a6 commit 4edcac1

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Copyright 2025 Open Source Robotics Foundation, Inc.
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+
# Base Classes
16+
from abc import ABC
17+
from abc import ABCMeta
18+
from abc import abstractmethod
19+
from typing import Any
20+
from typing import ClassVar
21+
from typing import Generic
22+
from typing import TypeVar
23+
24+
25+
class MessageTypeSupportMeta(ABCMeta):
26+
27+
_CREATE_ROS_MESSAGE: ClassVar[Any]
28+
_CONVERT_FROM_PY: ClassVar[Any]
29+
_CONVERT_TO_PY: ClassVar[Any]
30+
_DESTROY_ROS_MESSAGE: ClassVar[Any]
31+
_TYPE_SUPPORT: ClassVar[Any]
32+
33+
@classmethod
34+
@abstractmethod
35+
def __import_type_support__(cls) -> None: ...
36+
37+
38+
class BaseMessage(ABC, metaclass=MessageTypeSupportMeta):
39+
40+
__slots__ = ()
41+
42+
@abstractmethod
43+
def __repr__(self) -> str: ...
44+
45+
@abstractmethod
46+
def __eq__(self, other: object) -> bool: ...
47+
48+
@classmethod
49+
@abstractmethod
50+
def get_fields_and_field_types(cls) -> dict[str, str]: ...
51+
52+
53+
RequestT = TypeVar('RequestT')
54+
ResponseT = TypeVar('ResponseT')
55+
56+
57+
class ServiceTypeSupportMeta(ABCMeta):
58+
59+
_TYPE_SUPPORT: ClassVar[Any]
60+
61+
@classmethod
62+
@abstractmethod
63+
def __import_type_support__(cls) -> None: ...
64+
65+
66+
class BaseService(ABC, Generic[RequestT, ResponseT], metaclass=ServiceTypeSupportMeta):
67+
68+
Request: type[RequestT]
69+
Response: type[ResponseT]
70+
71+
72+
GoalT = TypeVar('GoalT')
73+
ResultT = TypeVar('ResultT')
74+
FeedbackT = TypeVar('FeedbackT')
75+
76+
77+
class ActionTypeSupportMeta(ABCMeta):
78+
79+
_TYPE_SUPPORT: ClassVar[Any]
80+
81+
@classmethod
82+
@abstractmethod
83+
def __import_type_support__(cls) -> None: ...
84+
85+
86+
class BaseAction(ABC, Generic[GoalT, ResultT, FeedbackT], metaclass=ActionTypeSupportMeta):
87+
88+
Goal: type[GoalT]
89+
Result: type[ResultT]
90+
Feedback: type[FeedbackT]

0 commit comments

Comments
 (0)