[cosmetics] update date in GPL header
[vuplus_xbmc] / xbmc / interfaces / swig / AddonModuleXbmc.i
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://www.xbmc.org
4  *
5  *  This Program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, write to
17  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18  *  http://www.gnu.org/copyleft/gpl.html
19  *
20  */
21
22 %module(directors="1") xbmc
23
24 %{
25 #include "interfaces/legacy/Player.h"
26 #include "interfaces/legacy/RenderCapture.h"
27 #include "interfaces/legacy/Keyboard.h"
28 #include "interfaces/legacy/ModuleXbmc.h"
29 #include "interfaces/legacy/Monitor.h"
30
31 using namespace XBMCAddon;
32 using namespace xbmc;
33
34 #if defined(__GNUG__) && (__GNUC__>4) || (__GNUC__==4 && __GNUC_MINOR__>=2)
35 #pragma GCC diagnostic ignored "-Wstrict-aliasing"
36 #endif
37 %}
38
39 // This is all about warning suppression. It's OK that these base classes are 
40 // not part of what swig parses.
41 %feature("knownbasetypes") XBMCAddon::xbmc "AddonClass,IPlayerCallback,AddonCallback"
42 %feature("knownapitypes") XBMCAddon::xbmc "XBMCAddon::xbmcgui::ListItem,XBMCAddon::xbmc::PlayListItem"
43
44 %include "interfaces/legacy/swighelper.h"
45
46 %feature("python:coerceToUnicode") XBMCAddon::xbmc::getLocalizedString "true"
47
48 %include "interfaces/legacy/ModuleXbmc.h"
49
50 %feature("director") Player;
51
52 %feature("python:method:play") Player
53 {
54     TRACE;
55     PyObject *pObject = NULL;
56     PyObject *pObjectListItem = NULL;
57     char bWindowed = false;
58     static const char *keywords[] = { "item", "listitem", "windowed", NULL };
59
60     if (!PyArg_ParseTupleAndKeywords(
61       args,
62       kwds,
63       (char*)"|OOb",
64       (char**)keywords,
65       &pObject,
66       &pObjectListItem,
67       &bWindowed))
68     {
69       return NULL;
70     }
71
72     try
73     {
74       Player* player = ((Player*)retrieveApiInstance((PyObject*)self,&PyXBMCAddon_xbmc_Player_Type,"play","XBMCAddon::xbmc::Player"));
75
76       // set fullscreen or windowed
77       bool windowed = (0 != bWindowed);
78
79       if (pObject == NULL)
80         player->playCurrent(windowed);
81       else if ((PyString_Check(pObject) || PyUnicode_Check(pObject)))
82       {
83         CStdString item;
84         PyXBMCGetUnicodeString(item,pObject,"item","Player::play");
85         XBMCAddon::xbmcgui::ListItem* pListItem = 
86           (pObjectListItem ? 
87            (XBMCAddon::xbmcgui::ListItem *)retrieveApiInstance(pObjectListItem,"p.XBMCAddon::xbmcgui::ListItem","XBMCAddon::xbmc::","play") :
88            NULL);
89         player->playStream(item,pListItem,windowed);
90       }
91       else // pObject must be a playlist
92         player->playPlaylist((PlayList *)retrieveApiInstance(pObject,"p.XBMCAddon::xbmc::PlayList","XBMCAddon::xbmc::","play"), windowed);
93     }
94     catch (const XbmcCommons::Exception& e)
95     { 
96       CLog::Log(LOGERROR,"Leaving Python method 'XBMCAddon_xbmc_Player_play'. Exception from call to 'play' '%s' ... returning NULL", e.GetMessage());
97       PyErr_SetString(PyExc_RuntimeError, e.GetMessage()); 
98       return NULL; 
99     }
100     catch (...)
101     {
102       CLog::Log(LOGERROR,"Unknown exception thrown from the call 'play'");
103       PyErr_SetString(PyExc_RuntimeError, "Unknown exception thrown from the call 'play'"); 
104       return NULL; 
105     }
106
107     Py_INCREF(Py_None);
108     return Py_None;
109   }
110
111 %feature("python:nokwds") XBMCAddon::xbmc::Keyboard::Keyboard "true"
112 %feature("python:nokwds") XBMCAddon::xbmc::Player::Player "true"
113 %feature("python:nokwds") XBMCAddon::xbmc::PlayList::PlayList "true"
114
115 %include "interfaces/legacy/Player.h"
116
117  // TODO: This needs to be done with a class that holds the Image
118  // data. A memory buffer type. Then a typemap needs to be defined
119  // for that type.
120 %feature("python:method:getImage") RenderCapture
121 {
122   RenderCapture* rc = ((RenderCapture*)retrieveApiInstance((PyObject*)self,&PyXBMCAddon_xbmc_RenderCapture_Type,"getImage","XBMCAddon::xbmc::RenderCapture"));
123   if (rc->GetUserState() != CAPTURESTATE_DONE)
124   {
125     PyErr_SetString(PyExc_SystemError, "illegal user state");
126     return NULL;
127   }
128   
129   Py_ssize_t size = rc->getWidth() * rc->getHeight() * 4;
130   return PyByteArray_FromStringAndSize((const char *)rc->GetPixels(), size);
131 }
132
133 %include "interfaces/legacy/RenderCapture.h"
134
135 %include "interfaces/legacy/InfoTagMusic.h"
136 %include "interfaces/legacy/InfoTagVideo.h"
137 %include "interfaces/legacy/Keyboard.h"
138 %include "interfaces/legacy/PlayList.h"
139
140 %feature("director") Monitor;
141
142 %include "interfaces/legacy/Monitor.h"
143
144