File: wx_core_sink_c_impl.cc

package info (click to toggle)
gr-fosphor 3.7.0.2.7b6b996-1~bpo8+1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 1,364 kB
  • sloc: python: 9,622; ansic: 3,211; cpp: 1,048; lisp: 609; xml: 260; makefile: 32
file content (123 lines) | stat: -rw-r--r-- 2,680 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
122
123
/* -*- c++ -*- */
/*
 * Copyright 2013-2014 Sylvain Munaut <tnt@246tNt.com>
 *
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3, or (at your option)
 * any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this software; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street,
 * Boston, MA 02110-1301, USA.
 */

#include <Python.h>

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "wx_core_sink_c_impl.h"


namespace gr {
  namespace fosphor {

wx_core_sink_c::sptr
wx_core_sink_c::make(PyObject *cb_init, PyObject *cb_fini,
                     PyObject *cb_swap, PyObject *cb_update)
{
	return gnuradio::get_initial_sptr(
		new wx_core_sink_c_impl(cb_init, cb_fini, cb_swap, cb_update)
	);
}

wx_core_sink_c_impl::wx_core_sink_c_impl(PyObject *cb_init, PyObject *cb_fini,
                                         PyObject *cb_swap, PyObject *cb_update)
  : base_sink_c("wx_core_sink_c"),
    d_cb_init(cb_init), d_cb_fini(cb_fini),
    d_cb_swap(cb_swap), d_cb_update(cb_update)
{
	/* Make sure we keep reference to callbacks */
	Py_INCREF(this->d_cb_init);
	Py_INCREF(this->d_cb_fini);
	Py_INCREF(this->d_cb_swap);
	Py_INCREF(this->d_cb_update);
}

wx_core_sink_c_impl::~wx_core_sink_c_impl()
{
	/* Release callbacks */
	Py_DECREF(this->d_cb_init);
	Py_DECREF(this->d_cb_fini);
	Py_DECREF(this->d_cb_swap);
	Py_DECREF(this->d_cb_update);
}


void
wx_core_sink_c_impl::pycall(PyObject *cb)
{
	PyObject *arglist;
	PyObject *result;

	PyGILState_STATE gstate;
	gstate = PyGILState_Ensure();

	arglist = Py_BuildValue("()");
	result = PyEval_CallObject(cb, arglist);
	Py_DECREF(arglist);

	if (result != NULL)
		Py_DECREF(result);

	PyGILState_Release(gstate);
}


void
wx_core_sink_c_impl::glctx_init()
{
	this->pycall(this->d_cb_init);
}

void
wx_core_sink_c_impl::glctx_swap()
{
	this->pycall(this->d_cb_swap);
}

void
wx_core_sink_c_impl::glctx_poll()
{
	/* Nothing to do */
}

void
wx_core_sink_c_impl::glctx_fini()
{
	this->pycall(this->d_cb_fini);
}

void
wx_core_sink_c_impl::glctx_update()
{
	this->pycall(this->d_cb_update);
}


void
wx_core_sink_c_impl::pycb_reshape(int width, int height)
{
	this->cb_reshape(width, height);
}

  } /* namespace fosphor */
} /* namespace gr */