File: function_call_macros.h

package info (click to toggle)
pytango 10.1.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,304 kB
  • sloc: python: 27,795; cpp: 16,150; sql: 252; sh: 152; makefile: 43
file content (64 lines) | stat: -rw-r--r-- 2,669 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
 * SPDX-FileCopyrightText: All Contributors to the PyTango project
 *
 * SPDX-License-Identifier: LGPL-3.0-or-later
 */

#pragma once

#include "common_header.h"
#include "convertors/type_casters.h"
#include "base_types_structures/exception.h"

#define CATCH_PY_EXCEPTION               \
    catch(py::error_already_set & eas) { \
        handle_python_exception(eas);    \
    }

#define GET_DEVICE                  \
    py::gil_scoped_acquire acquire; \
    py::object py_dev = py::cast(dev);

#define GET_PYTHON_METHOD(method_name) \
    py::gil_scoped_acquire gil;        \
    py::function py_method = py::get_override(this, #method_name);

#define CALL_PURE_VOID_METHOD(method_name, ...) \
    GET_PYTHON_METHOD(method_name)              \
    if(py_method) {                             \
        try {                                   \
            py_method(__VA_ARGS__);             \
        }                                       \
        CATCH_PY_EXCEPTION                      \
    };

#define CALL_PURE_RETURN_METHOD(return_type, method_name, ...) \
    GET_PYTHON_METHOD(method_name)                             \
    if(py_method) {                                            \
        try {                                                  \
            return py_method(__VA_ARGS__).cast<return_type>(); \
        }                                                      \
        CATCH_PY_EXCEPTION                                     \
    };                                                         \
    return;

#define CALL_VOID_METHOD(method_name, cpp_class, ...) \
    GET_PYTHON_METHOD(method_name)                    \
    if(py_method) {                                   \
        try {                                         \
            py_method(__VA_ARGS__);                   \
        }                                             \
        CATCH_PY_EXCEPTION                            \
    } else {                                          \
        cpp_class::method_name(__VA_ARGS__);          \
    };

#define CALL_RETURN_METHOD(return_type, method_name, cpp_class, ...) \
    GET_PYTHON_METHOD(method_name)                                   \
    if(py_method) {                                                  \
        try {                                                        \
            return py_method(__VA_ARGS__).cast<return_type>();       \
        }                                                            \
        CATCH_PY_EXCEPTION                                           \
    };                                                               \
    return cpp_class::method_name(__VA_ARGS__);