Skip to content

Commit

Permalink
pmt: add python getCaIds wrapper
Browse files Browse the repository at this point in the history
and move it to a SWIG interface file
  • Loading branch information
pieterg committed May 4, 2013
1 parent 9c918a0 commit 23ba503
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 31 deletions.
34 changes: 5 additions & 29 deletions lib/dvb/pmt.cpp
Expand Up @@ -314,42 +314,18 @@ void eDVBServicePMTHandler::OCready(int error)
m_OC.stop();
}

PyObject *eDVBServicePMTHandler::getCaIds(bool pair)
void eDVBServicePMTHandler::getCaIds(std::vector<int> &caids, std::vector<int> &ecmpids)
{
ePyObject ret;

program prog;

if ( !getProgramInfo(prog) )
if (!getProgramInfo(prog))
{
if (pair)
for (std::list<program::capid_pair>::iterator it = prog.caids.begin(); it != prog.caids.end(); ++it)
{
int cnt=prog.caids.size();
if (cnt)
{
ret=PyList_New(cnt);
std::list<program::capid_pair>::iterator it(prog.caids.begin());
while(cnt--)
{
ePyObject tuple = PyTuple_New(2);
PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong(it->caid));
PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong((it++)->capid));
PyList_SET_ITEM(ret, cnt, tuple);
}
}
}
else
{
std::set<program::capid_pair> set(prog.caids.begin(), prog.caids.end());
std::set<program::capid_pair>::iterator it(set.begin());
int cnt=set.size();
ret=PyList_New(cnt);
while(cnt--)
PyList_SET_ITEM(ret, cnt, PyInt_FromLong((it++)->caid));
caids.push_back(it->caid);
ecmpids.push_back(it->capid);
}
}

return ret ? (PyObject*)ret : (PyObject*)PyList_New(0);
}

int eDVBServicePMTHandler::getProgramInfo(program &program)
Expand Down
2 changes: 1 addition & 1 deletion lib/dvb/pmt.h
Expand Up @@ -120,7 +120,7 @@ class eDVBServicePMTHandler: public eDVBPMTParser
int getProgramInfo(program &program);
int getDataDemux(ePtr<iDVBDemux> &demux);
int getDecodeDemux(ePtr<iDVBDemux> &demux);
PyObject *getCaIds(bool pair=false); // caid / ecmpid pair
void getCaIds(std::vector<int> &caids, std::vector<int> &ecmpids);

int getPVRChannel(ePtr<iDVBPVRChannel> &pvr_channel);
int getServiceReference(eServiceReferenceDVB &service) { service = m_reference; return 0; }
Expand Down
3 changes: 2 additions & 1 deletion lib/python/Makefile.inc
Expand Up @@ -25,7 +25,8 @@ EXTRA_DIST += \
python/python_service.i \
python/python_dvb.i \
python/python_base.i \
python/python_console.i
python/python_console.i \
python/python_pmt.i

@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/python/enigma_python.Pcpp@am__quote@

Expand Down
1 change: 1 addition & 0 deletions lib/python/enigma_python.i
Expand Up @@ -148,6 +148,7 @@ typedef long time_t;
%include <lib/python/python_dvb.i>
%include <lib/python/python_service.i>
%include <lib/python/python_pmt.i>
%immutable eSocketNotifier::activated;
%include <lib/base/ebase.h>
Expand Down
30 changes: 30 additions & 0 deletions lib/python/python_pmt.i
@@ -0,0 +1,30 @@
%extend eDVBServicePMTHandler {
PyObject *eDVBServicePMTHandler::getCaIds(bool pair)
{
ePyObject ret;
std::vector<int> caids, ecmpids;
self->getCaIds(caids, ecmpids);
int cnt = caids.size();

ret = PyList_New(cnt);

for (unsigned int i = 0; i < cnt; i++)
{
if (pair)
{
ePyObject tuple = PyTuple_New(2);
PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong(caids[i]));
PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(ecmpids[i]));
PyList_SET_ITEM(ret, i, tuple);
}
else
{
PyList_SET_ITEM(ret, i, PyInt_FromLong(caids[i]));
}
}

return ret;
}
};

%ignore eDVBServicePMTHandler::getCaIds;

0 comments on commit 23ba503

Please sign in to comment.