File: callback.h

package info (click to toggle)
pytango 10.0.2-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 10,216 kB
  • sloc: python: 28,206; cpp: 16,380; sql: 255; sh: 82; makefile: 43
file content (121 lines) | stat: -rw-r--r-- 4,560 bytes parent folder | download | duplicates (3)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
 * SPDX-FileCopyrightText: All Contributors to the PyTango project
 *
 * SPDX-License-Identifier: LGPL-3.0-or-later
 */

#pragma once

#include <map>
#include "defs.h"

/// Tango expects an object for callbacks derived from Tango::CallBack.
/// For read_attribute_asynch, write_attribute_asynch, the callback object
/// should be available until the callback is run. Then it can disappear.
/// Also if we forget about a DeviceProxy we don't need the callback anymore.
/// For event subscription however, the requirements are different. The C++
/// callback can be called way after the original DeviceProxy has disappered.
/// So for this case, the callback should live forever. As we don't want it,
/// we implemented the deletion of the callback in the DeviceProxy destructor
/// itself, after performing an unsubscribe.
/// @todo this is for cmd_ended, attr_read and attr_written. push_event are not done!
class PyCallBackAutoDie : public Tango::CallBack, public bopy::wrapper<Tango::CallBack>
{
  public:
    PyCallBackAutoDie() :
        m_self(0),
        m_weak_parent(0),
        m_extract_as(PyTango::ExtractAsNumpy)
    {
    }

    virtual ~PyCallBackAutoDie();

    //! It is the PyCallBackAutoDie object itself, as seen from python
    PyObject *m_self;
    //! The object that will call this callback, so we can
    //! monitor if it disappears, we are not needed anymore.
    PyObject *m_weak_parent;

    PyTango::ExtractAs m_extract_as;

    static std::map<PyObject *, PyObject *> s_weak2ob;
    static bopy::object py_on_callback_parent_fades;

    static void on_callback_parent_fades(PyObject *weakobj);
    static void init();

    void set_autokill_references(bopy::object &py_self, bopy::object &py_parent);
    void unset_autokill_references();

    void set_extract_as(PyTango::ExtractAs extract_as)
    {
        this->m_extract_as = extract_as;
    }

    bopy::object get_override(const char *name)
    {
        return bopy::wrapper<Tango::CallBack>::get_override(name);
    }

    virtual void cmd_ended(Tango::CmdDoneEvent *ev);
    virtual void attr_read(Tango::AttrReadEvent *ev);
    virtual void attr_written(Tango::AttrWrittenEvent *ev);
    //     virtual void push_event(Tango::EventData *ev);
    //     virtual void push_event(Tango::AttrConfEventData *ev);
    //     virtual void push_event(Tango::DataReadyEventData *ev);
};

class PyCallBackPushEvent : public Tango::CallBack, public bopy::wrapper<Tango::CallBack>
{
  public:
    PyCallBackPushEvent() :
        m_weak_device(0),
        m_extract_as(PyTango::ExtractAsNumpy)
    {
    }

    virtual ~PyCallBackPushEvent();

    //! The object that will call this callback (DeviceProxy), so we can
    //! monitor if it disappears, we are not needed anymore.
    PyObject *m_weak_device;
    PyTango::ExtractAs m_extract_as;

    void set_device(bopy::object &py_device);

    void set_extract_as(PyTango::ExtractAs extract_as)
    {
        this->m_extract_as = extract_as;
    }

    bopy::object get_override(const char *name);

    //     virtual void cmd_ended(Tango::CmdDoneEvent * ev);
    //     virtual void attr_read(Tango::AttrReadEvent *ev);
    //     virtual void attr_written(Tango::AttrWrittenEvent *ev);
    virtual void push_event(Tango::EventData *ev);
    virtual void push_event(Tango::AttrConfEventData *ev);
    virtual void push_event(Tango::DataReadyEventData *ev);
    virtual void push_event(Tango::PipeEventData *ev);
    virtual void push_event(Tango::DevIntrChangeEventData *ev);

    static void
        fill_py_event(Tango::EventData *ev, bopy::object &py_ev, bopy::object py_device, PyTango::ExtractAs extract_as);
    static void fill_py_event(Tango::AttrConfEventData *ev,
                              bopy::object &py_ev,
                              bopy::object py_device,
                              PyTango::ExtractAs extract_as);
    static void fill_py_event(Tango::DataReadyEventData *ev,
                              bopy::object &py_ev,
                              bopy::object py_device,
                              PyTango::ExtractAs extract_as);
    static void fill_py_event(Tango::PipeEventData *ev,
                              bopy::object &py_ev,
                              bopy::object py_device,
                              PyTango::ExtractAs extract_as);
    static void fill_py_event(Tango::DevIntrChangeEventData *ev,
                              bopy::object &py_ev,
                              bopy::object py_device,
                              PyTango::ExtractAs extract_as);
};