From: Felix Domke Date: Fri, 1 Oct 2004 13:21:35 +0000 (+0000) Subject: - add python, missing gui X-Git-Tag: 2.6.0~5953 X-Git-Url: https://git.cweiske.de/enigma2.git/commitdiff_plain/ddc3964ed95d01e72229dc9af968a327cd84e56c - add python, missing gui - remove console (needs to be rewritten anyway) - eString -> std::string --- diff --git a/configure.ac b/configure.ac index 19dee31b..7768a973 100644 --- a/configure.ac +++ b/configure.ac @@ -15,14 +15,13 @@ TUXBOX_APPS_LIB_CONFIG(FREETYPE,freetype-config) #TUXBOX_APPS_LIB_PKGCONFIG(FRIBIDI,fribidi) TUXBOX_APPS_LIB_PKGCONFIG(ID3TAG,id3tag) TUXBOX_APPS_LIB_PKGCONFIG(MAD,mad) -TUXBOX_APPS_LIB_PKGCONFIG(MD5SUM,tuxbox-md5sum) #TUXBOX_APPS_LIB_PKGCONFIG(PLUGINS,tuxbox-plugins) TUXBOX_APPS_LIB_PKGCONFIG(PNG,libpng) TUXBOX_APPS_LIB_PKGCONFIG(SIGC,sigc++-1.2) TUXBOX_APPS_LIB_PKGCONFIG(XMLTREE,tuxbox-xmltree) -CPPFLAGS="$CPPFLAGS $FREETYPE_CFLAGS $FRIBIDI_CFLAGS $ID3TAG_CFLAGS $MAD_CFLAGS $MD5SUM_CFLAGS $PLUGINS_CFLAGS $PNG_CFLAGS $SIGC_CFLAGS $XMLTREE_CFLAGS" -CXXFLAGS="$CXXFLAGS -fno-rtti -fno-exceptions" +CPPFLAGS="$CPPFLAGS $FREETYPE_CFLAGS $FRIBIDI_CFLAGS $ID3TAG_CFLAGS $MAD_CFLAGS $PLUGINS_CFLAGS $PNG_CFLAGS $SIGC_CFLAGS $XMLTREE_CFLAGS" +CXXFLAGS="$CXXFLAGS -fno-rtti -fno-exceptions -Wall" TUXBOX_APPS_GETTEXT @@ -30,6 +29,7 @@ AC_OUTPUT([ Makefile lib/Makefile lib/base/Makefile +lib/content/Makefile lib/driver/Makefile lib/dvb/Makefile lib/dvb_si/Makefile @@ -37,6 +37,7 @@ lib/gdi/Makefile lib/gui/Makefile lib/nav/Makefile lib/network/Makefile +lib/python/Makefile lib/service/Makefile main/Makefile ]) diff --git a/lib/Makefile.am b/lib/Makefile.am index 2ff99926..f33133b8 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1 +1 @@ -SUBDIRS = base dvb dvb_si gdi network service driver nav content gui +SUBDIRS = base dvb dvb_si gdi network service driver nav content gui python diff --git a/lib/base/Makefile.am b/lib/base/Makefile.am index 3e695a39..955d9e4a 100644 --- a/lib/base/Makefile.am +++ b/lib/base/Makefile.am @@ -4,6 +4,6 @@ INCLUDES = \ noinst_LIBRARIES = libenigma_base.a libenigma_base_a_SOURCES = \ - buffer.cpp console.cpp ebase.cpp econfig.cpp eerror.cpp elock.cpp \ - estring.cpp init.cpp message.cpp nconfig.cpp nxml.cpp thread.cpp \ - smartptr.cpp + buffer.cpp ebase.cpp econfig.cpp eerror.cpp elock.cpp \ + init.cpp message.cpp thread.cpp \ + smartptr.cpp estring.cpp diff --git a/lib/base/console.cpp b/lib/base/console.cpp deleted file mode 100644 index 2609582f..00000000 --- a/lib/base/console.cpp +++ /dev/null @@ -1,248 +0,0 @@ -/* - * console.cpp - * - * Copyright (C) 2002 Felix Domke - * - * This program 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 2 of the License, or - * (at your option) any later version. - * - * This program 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 program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * $Id: console.cpp,v 1.1 2003-10-17 15:35:47 tmbinc Exp $ - */ - -#include - -#include -#include // for statfs -#include -#include -#include - -int bidirpipe(int pfd[], char *cmd , char *argv[]) -{ - int pfdin[2]; /* from child to parent */ - int pfdout[2]; /* from parent to child */ - int pfderr[2]; /* stderr from child to parent */ - int pid; /* child's pid */ - - if ( pipe(pfdin) == -1 || pipe(pfdout) == -1 || pipe(pfderr) == -1) - return(-1); - - if ( ( pid = fork() ) == -1 ) - return(-1); - else if (pid == 0) /* child process */ - { - if ( close(0) == -1 || close(1) == -1 || close(2) == -1 ) - _exit(0); - - if (dup(pfdout[0]) != 0 || dup(pfdin[1]) != 1 || dup(pfderr[1]) != 2 ) - _exit(0); - - if (close(pfdout[0]) == -1 || close(pfdout[1]) == -1 || - close(pfdin[0]) == -1 || close(pfdin[1]) == -1 || - close(pfderr[0]) == -1 || close(pfderr[1]) == -1 ) - _exit(0); - - execv(cmd,argv); - _exit(0); - } - if (close(pfdout[0]) == -1 || close(pfdin[1]) == -1 || close(pfderr[1]) == -1) - return(-1); - - pfd[0] = pfdin[0]; - pfd[1] = pfdout[1]; - pfd[2] = pfderr[0]; - - return(pid); -} - -eConsoleAppContainer::eConsoleAppContainer( const eString &cmd ) -:pid(-1), killstate(0), outbuf(0) -{ -// eDebug("cmd = %s", cmd.c_str() ); - memset(fd, 0, sizeof(fd) ); - int cnt=2; // path to app + terminated 0 - eString str(cmd?cmd:""); - - while( str.length() && str[0] == ' ' ) // kill spaces at beginning - str = str.mid(1); - - while( str.length() && str[str.length()-1] == ' ' ) // kill spaces at the end - str = str.left( str.length() - 1 ); - - if (!str.length()) - return; - - unsigned int idx=0; - eString path = str.left( (idx = str.find(' ')) != eString::npos ? idx : str.length() ); -// eDebug("path = %s", path.c_str() ); - - eString cmds = str.mid( path.length()+1 ); -// eDebug("cmds = %s", cmds.c_str() ); - - idx = 0; - while ( (idx = cmds.find(' ',idx) ) != eString::npos ) // count args - { - cnt++; - idx++; - } - -// eDebug("idx = %d, %d counted spaces", idx, cnt-2); - - if ( cmds.length() ) - { - cnt++; -// eDebug("increase cnt"); - } - -// eDebug("%d args", cnt-2); - char **argv = new char*[cnt]; // min two args... path and terminating 0 - argv[0] = new char[ path.length() ]; - strcpy( argv[0], path.c_str() ); - argv[cnt-1] = 0; // set terminating null - - if ( cnt > 2 ) // more then default args? - { - cnt=1; // do not overwrite path in argv[0] - - while ( (idx = cmds.find(' ')) != eString::npos ) // parse all args.. - { - argv[cnt] = new char[ idx ]; -// eDebug("idx=%d, arg = %s", idx, cmds.left(idx).c_str() ); - strcpy( argv[cnt++], cmds.left( idx ).c_str() ); - cmds = cmds.mid(idx+1); -// eDebug("str = %s", cmds.c_str() ); - } - // store the last arg - argv[cnt] = new char[ cmds.length() ]; - strcpy( argv[cnt], cmds.c_str() ); - } - - // get one read ,one write and the err pipe to the prog.. - - if ( (pid = bidirpipe(fd, argv[0], argv)) == -1 ) - { - while ( cnt-- > 0 ) - delete [] argv[cnt]; - delete [] argv; - return; - } - - while ( cnt-- > 0 ) // release heap memory - delete [] argv[cnt]; - delete [] argv; - - eDebug("pipe in = %d, out = %d, err = %d", fd[0], fd[1], fd[2]); - - in = new eSocketNotifier(eApp, fd[0], 19 ); // 19 = POLLIN, POLLPRI, POLLHUP - out = new eSocketNotifier(eApp, fd[1], eSocketNotifier::Write); // POLLOUT - err = new eSocketNotifier(eApp, fd[2], 19 ); // 19 = POLLIN, POLLPRI, POLLHUP - CONNECT(in->activated, eConsoleAppContainer::readyRead); - CONNECT(out->activated, eConsoleAppContainer::readyWrite); - CONNECT(err->activated, eConsoleAppContainer::readyErrRead); - signal(SIGCHLD, SIG_IGN); // no zombie when child killed -} - -eConsoleAppContainer::~eConsoleAppContainer() -{ - if ( running() ) - { - killstate=-1; - kill(); - } - if ( outbuf ) - delete [] outbuf; -} - -void eConsoleAppContainer::kill() -{ - killstate=-1; - system( eString().sprintf("kill %d", pid).c_str() ); - eDebug("user kill console App"); -} - -void eConsoleAppContainer::closePipes() -{ - in->stop(); - out->stop(); - err->stop(); - ::close(fd[0]); - fd[0]=0; - ::close(fd[1]); - fd[1]=0; - ::close(fd[2]); - fd[2]=0; - eDebug("pipes closed"); -} - -void eConsoleAppContainer::readyRead(int what) -{ - if (what & POLLPRI|POLLIN) - { - eDebug("what = %d"); - char buf[2048]; - int readed = read(fd[0], buf, 2048); - eDebug("%d bytes read", readed); - if ( readed != -1 && readed ) - /*emit*/ dataAvail( eString( buf ) ); - else if (readed == -1) - eDebug("readerror %d", errno); - } - if (what & eSocketNotifier::Hungup) - { - eDebug("child has terminated"); - closePipes(); - /*emit*/ appClosed(killstate); - } -} - -void eConsoleAppContainer::readyErrRead(int what) -{ - if (what & POLLPRI|POLLIN) - { - eDebug("what = %d"); - char buf[2048]; - int readed = read(fd[2], buf, 2048); - eDebug("%d bytes read", readed); - if ( readed != -1 && readed ) - /*emit*/ dataAvail( eString( buf ) ); - else if (readed == -1) - eDebug("readerror %d", errno); - } -} - -void eConsoleAppContainer::write( const eString & str ) -{ - outbuf = new char[ str.length()]; - strcpy( outbuf, str.c_str() ); -} - -void eConsoleAppContainer::readyWrite(int what) -{ - if (what == 4 && outbuf) - { - if ( ::write( fd[1], outbuf, strlen(outbuf) ) != (int) strlen(outbuf) ) - { - /* emit */ dataSent(-1); - eDebug("writeError"); - } - else - { - /* emit */ dataSent(0); - eDebug("write ok"); - } - - delete outbuf; - outbuf=0; - } -} diff --git a/lib/base/console.h b/lib/base/console.h deleted file mode 100644 index e69de29b..00000000 diff --git a/lib/base/econfig.cpp b/lib/base/econfig.cpp index 3d51255b..e69de29b 100644 --- a/lib/base/econfig.cpp +++ b/lib/base/econfig.cpp @@ -1,43 +0,0 @@ -#include -#include -#include -#include -#include - -eConfig *eConfig::instance; - -eConfig::eConfig() -{ - if (!instance) - instance=this; - - setName(CONFIGDIR "/enigma/registry"); - int e=open(); - if (e == NC_ERR_CORRUPT) - { - eWarning("CORRUTPED REGISTRY!"); - ::remove(CONFIGDIR "/enigma/registry"); - } - if (e) - { - if (createNew()) - { - mkdir(CONFIGDIR "/enigma", 0777); - if (createNew()) - eFatal("error while opening/creating registry - create " CONFIGDIR "/enigma"); - } - if (open()) - eFatal("still can't open configfile"); - } - locked=1; - ppin=0; - getKey("/elitedvb/pins/parentallock", ppin ); -} - -eConfig::~eConfig() -{ - if (instance==this) - instance=0; -} - -eAutoInitP0 init_eRCConfig(eAutoInitNumbers::configuration, "Configuration"); diff --git a/lib/base/econfig.h b/lib/base/econfig.h index d9f3becd..e69de29b 100644 --- a/lib/base/econfig.h +++ b/lib/base/econfig.h @@ -1,27 +0,0 @@ -#ifndef __econfig_h -#define __econfig_h - -#include - -class eConfig: public NConfig -{ - static eConfig *instance; - int ppin; -public: - int locked; - static eConfig *getInstance() { return instance; } - void setParentalPin( int pin ) - { - ppin = pin; - setKey("/elitedvb/pins/parentallock", ppin ); - } - int getParentalPin() { return ppin; } - bool pLockActive() - { - return ppin && locked; - } - eConfig(); - ~eConfig(); -}; - -#endif diff --git a/lib/base/eerror.cpp b/lib/base/eerror.cpp index 68541d41..11bb9943 100644 --- a/lib/base/eerror.cpp +++ b/lib/base/eerror.cpp @@ -4,13 +4,13 @@ #include #include -#include +#include // #include int infatal=0; -Signal2 logOutput; +Signal2 logOutput; int logOutputConsole=1; void eFatal(const char* fmt, ...) @@ -43,7 +43,7 @@ void eDebug(const char* fmt, ...) va_start(ap, fmt); vsnprintf(buf, 1024, fmt, ap); va_end(ap); - logOutput(lvlDebug, eString(buf) + "\n"); + logOutput(lvlDebug, std::string(buf) + "\n"); if (logOutputConsole) fprintf(stderr, "%s\n", buf); } @@ -67,7 +67,7 @@ void eWarning(const char* fmt, ...) va_start(ap, fmt); vsnprintf(buf, 1024, fmt, ap); va_end(ap); - logOutput(lvlWarning, eString(buf) + "\n"); + logOutput(lvlWarning, std::string(buf) + "\n"); if (logOutputConsole) fprintf(stderr, "%s\n", buf); } diff --git a/lib/base/eerror.h b/lib/base/eerror.h index bf913959..476029c7 100644 --- a/lib/base/eerror.h +++ b/lib/base/eerror.h @@ -9,12 +9,12 @@ void eFatal(const char* fmt, ...); -class eString; - enum { lvlDebug=1, lvlWarning=2, lvlFatal=4 }; -extern Signal2 logOutput; +#ifndef SWIG +extern Signal2 logOutput; extern int logOutputConsole; +#endif #ifdef ASSERT #undef ASSERT @@ -24,7 +24,9 @@ extern int logOutputConsole; void eDebug(const char* fmt, ...); void eDebugNoNewLine(const char* fmt, ...); void eWarning(const char* fmt, ...); +#ifndef SWIG #define ASSERT(x) { if (!(x)) eFatal("%s:%d ASSERTION %s FAILED!", __FILE__, __LINE__, #x); } +#endif #else inline void eDebug(const char* fmt, ...) { diff --git a/lib/base/estring.cpp b/lib/base/estring.cpp index bf30d5f9..f0107b6a 100644 --- a/lib/base/estring.cpp +++ b/lib/base/estring.cpp @@ -1,27 +1,12 @@ -#include +#include #include #include #include +#include static pthread_mutex_t lock=PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP; -///////////////////////////////////////// eString sprintf ///////////////////////////////////////////////// -eString& eString::sprintf(char *fmt, ...) -{ - singleLock s(lock); -// Implements the normal sprintf method, to use format strings with eString -// The max length of the result string is 1024 char. - static char buf[1024]; - va_list ap; - va_start(ap, fmt); - std::vsnprintf(buf, 1024, fmt, ap); - va_end(ap); - assign(buf); - return *this; -} - -///////////////////////////////////////// eString setNum(uint, uint) /////////////////////////////////////// -eString& eString::setNum(int val, int sys) +std::string getNum(int val, int sys) { // Returns a string that contain the value val as string // if sys == 16 than hexadezimal if sys == 10 than decimal @@ -32,91 +17,9 @@ eString& eString::setNum(int val, int sys) else if (sys == 16) std::snprintf(buf, 12, "%X", val); - assign(buf); - return *this; -} - -///////////////////////////////////////// eString replaceChars(char, char) ///////////////////////////// -eString& eString::removeChars(char fchar) -{ -// Remove all chars that equal to fchar, and returns a reference to itself - unsigned int index=0; - - while ( ( index = find(fchar, index) ) != npos ) - erase(index, 1); - - return *this; -} - -/////////////////////////////////////// eString upper() //////////////////////////////////////////////// -eString& eString::upper() -{ -// convert all lowercase characters to uppercase, and returns a reference to itself - for (iterator it = begin(); it != end(); it++) - switch(*it) - { - case 'a' ... 'z' : - *it -= 32; - break; - - case 'ä' : - *it = 'Ä'; - break; - - case 'ü' : - *it = 'Ü'; - break; - - case 'ö' : - *it = 'Ö'; - break; - } - - return *this; -} - -eString& eString::strReplace(const char* fstr, const eString& rstr) -{ -// replace all occurrence of fstr with rstr and, and returns a reference to itself - unsigned int index=0; - unsigned int fstrlen = strlen(fstr); - int rstrlen=rstr.size(); - - while ( ( index = find(fstr, index) ) != npos ) - { - replace(index, fstrlen, rstr); - index+=rstrlen; - } - - return *this; -} - -int strnicmp(const char *s1, const char *s2, int len) -{ -// makes a case insensitive string compare with len Chars - while ( *s1 && *s2 && len-- ) - if ( tolower(*s1) != tolower(*s2) ) - return tolower(*s1) < tolower(*s2) ? -1 : 1; - else - s1++, s2++; - - return 0; -} - -/////////////////////////////////////// eString icompare(const eString&) //////////////////////////////////////////////// -int eString::icompare(const eString& s) -{ -// makes a case insensitive string compare - std::string::const_iterator p = begin(), - p2 = s.begin(); - - while ( p != end() && p2 != s.end() ) - if ( tolower(*p) != tolower(*p2) ) - return tolower(*p) < tolower(*p2) ? -1 : 1; - else - p++, p2++; - - return length() == s.length() ? 0 : length() < s.length() ? -1 : 1; + std::string res; + res.assign(buf); + return res; } // 8859-x to dvb coding tables. taken from www.unicode.org/Public/MAPPINGS/ISO8859/ @@ -278,7 +181,7 @@ static inline unsigned int recode(unsigned char d, int cp) } } -eString convertDVBUTF8(unsigned char *data, int len, int table) +std::string convertDVBUTF8(unsigned char *data, int len, int table) { int i; if (!len) @@ -349,12 +252,12 @@ eString convertDVBUTF8(unsigned char *data, int len, int table) } if ( t != bytesneeded) eFatal("t: %d, bytesneeded: %d", t, bytesneeded); - return eString().assign((char*)res, t); + return std::string().assign((char*)res, t); } -eString convertUTF8DVB(const eString &string) +std::string convertUTF8DVB(const std::string &string) { - eString ss=eString(); + std::string ss=std::string(); int len=string.length(); for(int i=0;i= length() ? *this : substr(0, len); -} - -//////////////////////////////////////// eString mid //////////////////////////////////////////////////////////// -inline eString eString::mid(unsigned int index, unsigned int len) const -{ -// Returns a substring that contains the len characters of this string, starting at position index. -// Returns a null string if the string is empty or index is out of range. Returns the whole string from index if index+len exceeds the length of the string. - register unsigned int strlen = length(); - - if (index >= strlen) - return eString(); - - if (len == (unsigned)-1) - return substr(index); - - if (strlen < index + len) - len = strlen-index; - - return substr(index, len); -} - -//////////////////////////////////////// eString right //////////////////////////////////////////////////////////// -inline eString eString::right(unsigned int len) const -{ -// Returns a substring that contains the len rightmost characters of the string. -// The whole string is returned if len exceeds the length of the string. - register unsigned int strlen = length(); - return len >= strlen ? *this : substr(strlen-len, len); -} - -inline bool eString::isNull() const -{ -// Returns a bool, that contains true, when the internal char* is null (only when a string ist empty constructed) - return !c_str(); -} +std::string getNum(int num, int base=10); +std::string convertDVBUTF8(unsigned char *data, int len, int table=5); +std::string convertUTF8DVB(const std::string &string); // with default ISO8859-5 +std::string convertLatin1UTF8(const std::string &string); +int isUTF8(const std::string &string); #endif // __E_STRING__ diff --git a/lib/base/smartptr.h b/lib/base/smartptr.h index aafecf0e..906bba69 100644 --- a/lib/base/smartptr.h +++ b/lib/base/smartptr.h @@ -7,22 +7,6 @@ template class ePtr { - /* read doc/iObject about the ePtrHelper */ - template - class ePtrHelper - { - T1 *m_obj; - public: - inline ePtrHelper(T1 *obj): m_obj(obj) - { - m_obj->AddRef(); - } - inline ~ePtrHelper() - { - m_obj->Release(); - } - inline T1* operator->() { return m_obj; } - }; protected: T *ptr; public: @@ -69,15 +53,62 @@ public: T* grabRef() { if (!ptr) return 0; ptr->AddRef(); return ptr; } T* &ptrref() { assert(!ptr); return ptr; } + T* operator->() const { assert(ptr); return ptr; } + operator T*() const { return this->ptr; } +}; + + + +#ifndef SWIG +template +class eMutablePtr: public ePtr +{ + /* read doc/iObject about the ePtrHelper */ + template + class ePtrHelper + { + T1 *m_obj; + public: + inline ePtrHelper(T1 *obj): m_obj(obj) + { + m_obj->AddRef(); + } + inline ~ePtrHelper() + { + m_obj->Release(); + } + inline T1* operator->() { return m_obj; } + }; +protected: + T *ptr; +public: + eMutablePtr(): ePtr(0) + { + } + + eMutablePtr(T *c): ePtr(c) + { + } + + eMutablePtr(const eMutablePtr &c): ePtr(c) + { + } + + eMutablePtr &operator=(T *c) + { + ePtr::operator=(c); + return *this; + } + + ePtrHelper operator->() { assert(ptr); return ePtrHelper(ptr); } /* for const objects, we don't need the helper, as they can't */ /* be changed outside the program flow. at least this is */ /* what the compiler assumes, so in case you're using const */ - /* ePtrs note that they have to be const. */ + /* eMutablePtrs note that they have to be const. */ const T* operator->() const { assert(ptr); return ptr; } - operator T*() const { return this->ptr; } }; - +#endif #endif diff --git a/lib/driver/rc.cpp b/lib/driver/rc.cpp index 790c5f6c..39206512 100644 --- a/lib/driver/rc.cpp +++ b/lib/driver/rc.cpp @@ -40,7 +40,7 @@ int eRCDevice::getKeyCompatibleCode(const eRCKey &) const return -1; } -eRCDevice::eRCDevice(eString id, eRCDriver *driver): driver(driver), id(id) +eRCDevice::eRCDevice(std::string id, eRCDriver *driver): driver(driver), id(id) { input=driver->getInput(); driver->addCodeListener(this); @@ -127,7 +127,7 @@ eRCInputEventDriver::eRCInputEventDriver(const char *filename): eRCDriver(eRCInp } } -eString eRCInputEventDriver::getDeviceName() +std::string eRCInputEventDriver::getDeviceName() { char name[128]=""; if (handle >= 0) @@ -214,30 +214,30 @@ void eRCInput::setFile(int newh) handle=newh; } -void eRCInput::addDevice(const eString &id, eRCDevice *dev) +void eRCInput::addDevice(const std::string &id, eRCDevice *dev) { - devices.insert(std::pair(id, dev)); + devices.insert(std::pair(id, dev)); } -void eRCInput::removeDevice(const eString &id) +void eRCInput::removeDevice(const std::string &id) { devices.erase(id); } -eRCDevice *eRCInput::getDevice(const eString &id) +eRCDevice *eRCInput::getDevice(const std::string &id) { - std::map::iterator i=devices.find(id); + std::map::iterator i=devices.find(id); if (i == devices.end()) { eDebug("failed, possible choices are:"); - for (std::map::iterator i=devices.begin(); i != devices.end(); ++i) + for (std::map::iterator i=devices.begin(); i != devices.end(); ++i) eDebug("%s", i->first.c_str()); return 0; } return i->second; } -std::map &eRCInput::getDevices() +std::map &eRCInput::getDevices() { return devices; } diff --git a/lib/driver/rc.h b/lib/driver/rc.h index 557be5ea..8d932f8e 100644 --- a/lib/driver/rc.h +++ b/lib/driver/rc.h @@ -6,7 +6,7 @@ #include #include -#include +#include class eRCInput; class eRCDriver; @@ -22,7 +22,7 @@ class eRCDevice: public Object protected: eRCInput *input; eRCDriver *driver; - eString id; + std::string id; public: /** * \brief Constructs a new remote control. @@ -30,7 +30,7 @@ public: * \param id The identifier of the RC, for use in settings. * \param input The \ref eRCDriver where this remote gets its codes from. */ - eRCDevice(eString id, eRCDriver *input); + eRCDevice(std::string id, eRCDriver *input); ~eRCDevice(); /** * \brief Handles a device specific code. @@ -45,7 +45,7 @@ public: * \result The description. */ virtual const char *getDescription() const=0; - const eString getIdentifier() const { return id; } + const std::string getIdentifier() const { return id; } /** * \brief Get a description for a specific key. * \param key The key to get the description for. @@ -116,7 +116,7 @@ protected: eSocketNotifier *sn; void keyPressed(int); public: - eString getDeviceName(); + std::string getDeviceName(); eRCInputEventDriver(const char *filename); ~eRCInputEventDriver(); }; @@ -179,13 +179,13 @@ class eRCInput: public Object public: struct lstr { - bool operator()(const eString &a, const eString &b) const + bool operator()(const std::string &a, const std::string &b) const { return a devices; + std::map devices; public: Signal1 keyEvent; enum @@ -213,10 +213,10 @@ public: /*emit*/ keyEvent(key); } - void addDevice(const eString &id, eRCDevice *dev); - void removeDevice(const eString &id); - eRCDevice *getDevice(const eString &id); - std::map &getDevices(); + void addDevice(const std::string &id, eRCDevice *dev); + void removeDevice(const std::string &id); + eRCDevice *getDevice(const std::string &id); + std::map &getDevices(); static eRCInput *getInstance() { return instance; } diff --git a/lib/driver/rcinput.cpp b/lib/driver/rcinput.cpp index 041330a1..94ce3ebe 100644 --- a/lib/driver/rcinput.cpp +++ b/lib/driver/rcinput.cpp @@ -1,5 +1,7 @@ #include +#include + #include #include #include diff --git a/lib/dvb/db.cpp b/lib/dvb/db.cpp index 5426fa4b..1a2cd7df 100644 --- a/lib/dvb/db.cpp +++ b/lib/dvb/db.cpp @@ -126,7 +126,7 @@ eDVBDB::eDVBDB() if (strlen(line)) line[strlen(line)-1]=0; - eString str=line; + std::string str=line; if (str[1]!=':') // old ... (only service_provider) { @@ -136,15 +136,15 @@ eDVBDB::eDVBDB() { unsigned int c=str.find(','); char p=str[0]; - eString v; - if (c == eString::npos) + std::string v; + if (c == std::string::npos) { - v=str.mid(2); + v=str.substr(2); str=""; } else { - v=str.mid(2, c-2); - str=str.mid(c+1); + v=str.substr(2, c-2); + str=str.substr(c+1); } // eDebug("%c ... %s", p, v.c_str()); if (p == 'p') diff --git a/lib/dvb/db.h b/lib/dvb/db.h index fe4833cd..5a67870d 100644 --- a/lib/dvb/db.h +++ b/lib/dvb/db.h @@ -9,8 +9,8 @@ class eDVBService: public iObject DECLARE_REF; public: eDVBService(); - eString m_service_name; - eString m_provider_name; + std::string m_service_name; + std::string m_provider_name; int m_flags; std::set m_ca; diff --git a/lib/dvb/decoder.cpp b/lib/dvb/decoder.cpp index 0b3619ad..da529046 100644 --- a/lib/dvb/decoder.cpp +++ b/lib/dvb/decoder.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/lib/dvb/pmt.cpp b/lib/dvb/pmt.cpp index 4ab551f1..292012e1 100644 --- a/lib/dvb/pmt.cpp +++ b/lib/dvb/pmt.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/lib/dvb/stT1RVV7 b/lib/dvb/stT1RVV7 index a9d6d3dc..e69de29b 100644 Binary files a/lib/dvb/stT1RVV7 and b/lib/dvb/stT1RVV7 differ diff --git a/lib/gdi/font.cpp b/lib/gdi/font.cpp index a8f0b120..ee228576 100644 --- a/lib/gdi/font.cpp +++ b/lib/gdi/font.cpp @@ -101,7 +101,7 @@ FT_Error fontRenderClass::FTC_Face_Requester(FTC_FaceID face_id, FT_Face* aface) return 0; } -FTC_FaceID fontRenderClass::getFaceID(const eString &face) +FTC_FaceID fontRenderClass::getFaceID(const std::string &face) { for (fontListEntry *f=font; f; f=f->next) { @@ -117,7 +117,7 @@ FT_Error fontRenderClass::getGlyphBitmap(FTC_Image_Desc *font, FT_ULong glyph_in return res; } -eString fontRenderClass::AddFont(const eString &filename, const eString &name, int scale) +std::string fontRenderClass::AddFont(const std::string &filename, const std::string &name, int scale) { eDebugNoNewLine("[FONT] adding font %s...", filename.c_str()); fflush(stdout); @@ -225,7 +225,7 @@ fontRenderClass::~fontRenderClass() // FT_Done_FreeType(library); } -int fontRenderClass::getFont(ePtr &font, const eString &face, int size, int tabwidth) +int fontRenderClass::getFont(ePtr &font, const std::string &face, int size, int tabwidth) { FTC_FaceID id=getFaceID(face); if (!id) @@ -400,7 +400,7 @@ void eTextPara::setFont(const gFont *font) setFont(fnt, replacement); } -eString eTextPara::replacement_facename; +std::string eTextPara::replacement_facename; void eTextPara::setFont(Font *fnt, Font *replacement) { @@ -437,7 +437,7 @@ void eTextPara::setFont(Font *fnt, Font *replacement) void shape (std::vector &string, const std::vector &text); -int eTextPara::renderString(const eString &string, int rflags) +int eTextPara::renderString(const std::string &string, int rflags) { singleLock s(ftlock); @@ -463,7 +463,7 @@ int eTextPara::renderString(const eString &string, int rflags) std::vector uc_string, uc_visual; uc_string.reserve(string.length()); - eString::const_iterator p(string.begin()); + std::string::const_iterator p(string.begin()); while(p != string.end()) { diff --git a/lib/gdi/font.cpp-new b/lib/gdi/font.cpp-new index e9aa5430..143374b4 100644 --- a/lib/gdi/font.cpp-new +++ b/lib/gdi/font.cpp-new @@ -434,7 +434,7 @@ void eTextPara::setFont(Font *fnt) use_kerning=FT_HAS_KERNING(current_face); } -int eTextPara::renderString(const eString &string, int rflags) +int eTextPara::renderString(const std::string &string, int rflags) { eLocker lock(ftlock); diff --git a/lib/gdi/font.h b/lib/gdi/font.h index 7b01a425..a17fee71 100644 --- a/lib/gdi/font.h +++ b/lib/gdi/font.h @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include class FontRenderClass; @@ -29,7 +29,7 @@ class fontRenderClass fbClass *fb; struct fontListEntry { - eString filename, face; + std::string filename, face; int scale; // 100 is 1:1 fontListEntry *next; ~fontListEntry(); @@ -40,16 +40,16 @@ class fontRenderClass FTC_Image_Cache imageCache; /* the glyph image cache */ FTC_SBit_Cache sbitsCache; /* the glyph small bitmaps cache */ - FTC_FaceID getFaceID(const eString &face); + FTC_FaceID getFaceID(const std::string &face); FT_Error getGlyphBitmap(FTC_Image_Desc *font, FT_ULong glyph_index, FTC_SBit *sbit); static fontRenderClass *instance; public: float getLineHeight(const gFont& font); - eString AddFont(const eString &filename, const eString &name, int scale); + std::string AddFont(const std::string &filename, const std::string &name, int scale); static fontRenderClass *getInstance(); FT_Error FTC_Face_Requester(FTC_FaceID face_id, FT_Face* aface); - int getFont(ePtr &font, const eString &face, int size, int tabwidth=-1); + int getFont(ePtr &font, const std::string &face, int size, int tabwidth=-1); fontRenderClass(); ~fontRenderClass(); }; @@ -85,7 +85,7 @@ private: FT_Face current_face, replacement_face; int use_kerning; int previous; - static eString replacement_facename; + static std::string replacement_facename; eRect area; ePoint cursor; @@ -107,10 +107,10 @@ public: } virtual ~eTextPara(); - static void setReplacementFont(eString font) { replacement_facename=font; } + static void setReplacementFont(std::string font) { replacement_facename=font; } void setFont(const gFont *font); - int renderString(const eString &string, int flags=0); + int renderString(const std::string &string, int flags=0); void clear(); diff --git a/lib/gdi/gpixmap.h b/lib/gdi/gpixmap.h index f0912334..9dd170ac 100644 --- a/lib/gdi/gpixmap.h +++ b/lib/gdi/gpixmap.h @@ -2,7 +2,7 @@ #define __gpixmap_h #include -#include +#include #include #include #include @@ -92,7 +92,7 @@ class gFont: public iObject DECLARE_REF; public: - eString family; + std::string family; int pointSize; /** @@ -100,7 +100,7 @@ public: * \param family The name of the font, for example "NimbusSansL-Regular Sans L Regular". * \param pointSize the size of the font in PIXELS. */ - gFont(const eString &family, int pointSize): + gFont(const std::string &family, int pointSize): family(family), pointSize(pointSize) { } diff --git a/lib/gdi/grc.h b/lib/gdi/grc.h index 0f66ef08..a02068ae 100644 --- a/lib/gdi/grc.h +++ b/lib/gdi/grc.h @@ -11,7 +11,7 @@ #include #include -#include +#include #include #include #include @@ -58,7 +58,7 @@ struct gOpcode struct prenderText { eRect area; - eString text; + std::string text; int flags; } *renderText; diff --git a/lib/gui/ebutton.cpp b/lib/gui/ebutton.cpp new file mode 100644 index 00000000..5c136abd --- /dev/null +++ b/lib/gui/ebutton.cpp @@ -0,0 +1,20 @@ +#include + +eButton::eButton(eWidget *parent): eLabel(parent) +{ +} + +void eButton::push() +{ + selected(); +} + +int eButton::event(int event, void *data, void *data2) +{ + switch (event) + { + default: + break; + } + return eLabel::event(event, data, data2); +} diff --git a/lib/gui/ebutton.h b/lib/gui/ebutton.h new file mode 100644 index 00000000..31c9cb3c --- /dev/null +++ b/lib/gui/ebutton.h @@ -0,0 +1,17 @@ +#ifndef __lib_gui_ebutton_h +#define __lib_gui_ebutton_h + +#include + +class eButton: public eLabel +{ +public: + eButton(eWidget *parent); + Signal0 selected; + + void push(); +protected: + int event(int event, void *data=0, void *data2=0); +}; + +#endif diff --git a/lib/gui/elabel.cpp b/lib/gui/elabel.cpp new file mode 100644 index 00000000..f133b661 --- /dev/null +++ b/lib/gui/elabel.cpp @@ -0,0 +1,39 @@ +#include + +eLabel::eLabel(eWidget *parent): eWidget(parent) +{ + +} + +int eLabel::event(int event, void *data, void *data2) +{ + switch (event) + { + case evtPaint: + { + gPainter &painter = *(gPainter*)data2; + ePtr fnt = new gFont("Arial", 70); + painter.setFont(fnt); + painter.setBackgroundColor(gColor(0x10)); + painter.setForegroundColor(gColor(0x1f)); + painter.clear(); + painter.setBackgroundColor(gColor(0x1f)); + painter.setForegroundColor(gColor(0x10)); + painter.renderText(eRect(0, 0, size().width(), size().height()), m_text); + return 0; + } + case evtChangedText: + invalidate(); + return 0; + default: + return eWidget::event(event, data, data2); + } +} + +void eLabel::setText(const std::string &string) +{ + if (m_text == string) + return; + m_text = string; + event(evtChangedText); +} diff --git a/lib/gui/elabel.h b/lib/gui/elabel.h new file mode 100644 index 00000000..b1f7c2cf --- /dev/null +++ b/lib/gui/elabel.h @@ -0,0 +1,21 @@ +#ifndef __lib_gui_elabel_h +#define __lib_gui_elabel_h + +#include + +class eLabel: public eWidget +{ +public: + eLabel(eWidget *parent); + void setText(const std::string &string); +protected: + int event(int event, void *data=0, void *data2=0); +private: + enum eLabelEvent + { + evtChangedText = evtUserWidget + }; + std::string m_text; +}; + +#endif diff --git a/lib/gui/ewidget.cpp b/lib/gui/ewidget.cpp new file mode 100644 index 00000000..89fbfe95 --- /dev/null +++ b/lib/gui/ewidget.cpp @@ -0,0 +1,167 @@ +#include +#include + +extern void dumpRegion(const gRegion ®ion); + +eWidget::eWidget(eWidget *parent): m_parent(parent) +{ + m_vis = 0; + m_desktop = 0; + + if (parent) + m_vis = wVisShow; + + if (parent) + parent->m_childs.push_back(this); +} + +void eWidget::move(ePoint pos) +{ + m_position = pos; + + event(evtChangedPosition); +} + +void eWidget::resize(eSize size) +{ + event(evtWillChangeSize, &size); + event(evtChangedSize); +} + +void eWidget::invalidate(const gRegion ®ion) +{ + gRegion res = /* region & */ m_visible_with_childs; + if (res.empty()) + return; + + eWidget *root = this; + ePoint abspos = position(); + while (root && !root->m_desktop) + { + root = root->m_parent; + assert(root); + abspos += root->position(); + } + + res.moveBy(abspos); +// eDebug("region to invalidate:"); +// dumpRegion(res); + root->m_desktop->invalidate(res); +} + +void eWidget::show() +{ + if (m_vis & wVisShow) + return; + + m_vis |= wVisShow; + + /* TODO: optimize here to only recalc what's required. possibly merge with hide. */ + eWidget *root = this; + ePoint abspos = position(); + while (root && !root->m_desktop) + { + root = root->m_parent; + assert(root); + abspos += root->position(); + } + + root->m_desktop->recalcClipRegions(); + + gRegion abs = m_visible_with_childs; + abs.moveBy(abspos); + root->m_desktop->invalidate(abs); +} + +void eWidget::hide() +{ + m_vis &= ~wVisShow; + + /* TODO: optimize here to only recalc what's required. possibly merge with show. */ + eWidget *root = this; + ePoint abspos = position(); + while (root && !root->m_desktop) + { + root = root->m_parent; + abspos += root->position(); + } + assert(root->m_desktop); + + gRegion abs = m_visible_with_childs; + abs.moveBy(abspos); + + root->m_desktop->recalcClipRegions(); + root->m_desktop->invalidate(abs); +} + +void eWidget::destruct() +{ + if (m_parent) + m_parent->m_childs.remove(this); + delete this; +} + +eWidget::~eWidget() +{ + /* destroy all childs */ + ePtrList::iterator i(m_childs.begin()); + while (i != m_childs.end()) + { + delete *i; + i = m_childs.erase(i); + } +} + +void eWidget::doPaint(gPainter &painter, const gRegion &r) +{ + if (m_visible_with_childs.empty()) + return; + + gRegion region = r; + /* we were in parent's space, now we are in local space */ + region.moveBy(-position()); + + painter.moveOffset(position()); + /* walk all childs */ + for (ePtrList::iterator i(m_childs.begin()); i != m_childs.end(); ++i) + i->doPaint(painter, region); + + /* check if there's anything for us to paint */ + region &= m_visible_region; + + painter.resetClip(region); + event(evtPaint, ®ion, &painter); + + painter.moveOffset(-position()); +} + +int eWidget::event(int event, void *data, void *data2) +{ + switch (event) + { + case evtPaint: + { + static int counter = 0x18; + gPainter &painter = *(gPainter*)data2; +// eDebug("eWidget::evtPaint %d", counter); +// dumpRegion(*(gRegion*)data); + painter.setBackgroundColor(gColor(++counter)); + painter.clear(); + break; + } + case evtKey: + break; + case evtWillChangeSize: + m_size = *static_cast(data); + break; + case evtChangedSize: + { + m_clip_region = gRegion(eRect(ePoint(0, 0), m_size)); + break; + } + default: + return -1; + } + return 0; +} + diff --git a/lib/gui/ewidget.h b/lib/gui/ewidget.h new file mode 100644 index 00000000..a551b8a3 --- /dev/null +++ b/lib/gui/ewidget.h @@ -0,0 +1,66 @@ +#ifndef __lib_gui_ewidget_h +#define __lib_gui_ewidget_h + +#include /* for gRegion */ +#include /* for eSmartPtrList */ + +class eWidget +{ + friend class eWidgetDesktop; +public: + eWidget(eWidget *parent); + + void move(ePoint pos); + void resize(eSize size); + + ePoint position() const { return m_position; } + eSize size() const { return m_size; } + + void invalidate(const gRegion ®ion = gRegion::invalidRegion()); + + void show(); + void hide(); + + void destruct(); +private: + eWidgetDesktop *m_desktop; + + enum { + wVisShow = 1, + wVisTransparent = 2, + }; + + int m_vis; + + ePtrList m_childs; + eWidget *m_parent; + ePoint m_position; + eSize m_size; + + + void doPaint(gPainter &painter, const gRegion ®ion); +protected: + virtual ~eWidget(); +public: + + // all in local space! + gRegion m_clip_region, m_visible_region, m_visible_with_childs; + + enum eWidgetEvent + { + evtPaint, + evtKey, + evtChangedPosition, + evtChangedSize, + + evtWillShow, + evtWillHide, + evtWillChangePosition, /* new size is eRect *data */ + evtWillChangeSize, + + evtUserWidget, + }; + virtual int event(int event, void *data = 0, void *data2 = 0); +}; + +#endif diff --git a/lib/gui/ewidgetdesktop.cpp b/lib/gui/ewidgetdesktop.cpp new file mode 100644 index 00000000..10c92b71 --- /dev/null +++ b/lib/gui/ewidgetdesktop.cpp @@ -0,0 +1,72 @@ +#include +#include + +void eWidgetDesktop::addRootWidget(eWidget *root, int top) +{ + assert(!root->m_desktop); + if (!top) + m_root.push_back(root); + else + m_root.push_front(root); + root->m_desktop = this; +} + +void eWidgetDesktop::calcWidgetClipRegion(eWidget *widget, gRegion &parent_visible) +{ + /* start with our clip region, clipped with the parent's */ + if (widget->m_vis & eWidget::wVisShow) + { + widget->m_visible_region = widget->m_clip_region; + widget->m_visible_region.moveBy(widget->position()); + widget->m_visible_region &= parent_visible; // in parent space! + /* TODO: check transparency here! */ + /* remove everything this widget will contain from parent's visible list */ + parent_visible -= widget->m_visible_region; // will remove child regions too! + + /* now prepare for recursing to childs */ + widget->m_visible_region.moveBy(-widget->position()); // now in local space + } else + widget->m_visible_region = gRegion(); + + widget->m_visible_with_childs = widget->m_visible_region; + + for (ePtrList::iterator i(widget->m_childs.begin()); i != widget->m_childs.end(); ++i) + calcWidgetClipRegion(*i, widget->m_visible_region); +} + +void eWidgetDesktop::recalcClipRegions() +{ + gRegion screen = gRegion(eRect(ePoint(0, 0), m_screen_size)); + + for (ePtrList::iterator i(m_root.begin()); i != m_root.end(); ++i) + calcWidgetClipRegion(*i, screen); +// dumpRegion(screen); +} + +void eWidgetDesktop::invalidate(const gRegion ®ion) +{ + m_dirty_region |= region; +} + +void eWidgetDesktop::paint() +{ + gPainter painter(m_dc); + /* walk all root windows. */ + for (ePtrList::iterator i(m_root.begin()); i != m_root.end(); ++i) + i->doPaint(painter, m_dirty_region); + m_dirty_region = gRegion(); +} + +void eWidgetDesktop::setDC(gDC *dc) +{ + m_dc = dc; +} + +eWidgetDesktop::eWidgetDesktop(eSize size): m_screen_size(size) +{ +} + +eWidgetDesktop::~eWidgetDesktop() +{ +} + diff --git a/lib/gui/ewidgetdesktop.h b/lib/gui/ewidgetdesktop.h new file mode 100644 index 00000000..197693f8 --- /dev/null +++ b/lib/gui/ewidgetdesktop.h @@ -0,0 +1,29 @@ +#ifndef __lib_gui_ewidgetdesktop_h +#define __lib_gui_ewidgetdesktop_h + +#include +#include + +class eWidget; + +class eWidgetDesktop +{ +public: // weil debug + eSize m_screen_size; + gRegion m_dirty_region; + ePtr m_dc; +public: + eWidgetDesktop(eSize screen); + ~eWidgetDesktop(); + void addRootWidget(eWidget *root, int top); + void recalcClipRegions(); + + void invalidate(const gRegion ®ion); + void paint(); + void setDC(gDC *dc); +private: + ePtrList m_root; + void calcWidgetClipRegion(eWidget *widget, gRegion &parent_visible); +}; + +#endif diff --git a/lib/gui/ewindow.cpp b/lib/gui/ewindow.cpp new file mode 100644 index 00000000..1afee2ee --- /dev/null +++ b/lib/gui/ewindow.cpp @@ -0,0 +1,46 @@ +#include +#include + +#include + +eWindow::eWindow(eWidgetDesktop *desktop): eWidget(0) +{ + m_child = new eWidget(this); + desktop->addRootWidget(this, 0); + + m_style = new eWindowStyleSimple(); +} + +void eWindow::setTitle(const std::string &string) +{ + if (m_title == string) + return; + m_title = string; + event(evtTitleChanged); +} + +int eWindow::event(int event, void *data, void *data2) +{ + switch (event) + { + case evtWillChangeSize: + { + const eSize &new_size = *static_cast(data); + eDebug("eWindow::evtWillChangeSize to %d %d", new_size.width(), new_size.height()); + if (m_style) + m_style->handleNewSize(this, new_size); + break; + } + case evtPaint: + { + gPainter &painter = *static_cast(data2); + painter.setBackgroundColor(gColor(0x18)); + painter.clear(); + break; + } + default: + break; + } + return eWidget::event(event, data, data2); +} + diff --git a/lib/gui/ewindow.h b/lib/gui/ewindow.h new file mode 100644 index 00000000..671a0079 --- /dev/null +++ b/lib/gui/ewindow.h @@ -0,0 +1,28 @@ +#ifndef __lib_gui_ewindow_h +#define __lib_gui_ewindow_h + +#include +#include + +class eWidgetDesktop; + +class eWindow: public eWidget +{ + friend class eWindowStyle; +public: + eWindow(eWidgetDesktop *desktop); + void setTitle(const std::string &string); + eWidget *child() { return m_child; } +protected: + enum eWindowEvents + { + evtTitleChanged = evtUserWidget, + }; + int event(int event, void *data=0, void *data2=0); +private: + std::string m_title; + eWidget *m_child; + ePtr m_style; +}; + +#endif diff --git a/lib/gui/ewindowstyle.cpp b/lib/gui/ewindowstyle.cpp new file mode 100644 index 00000000..932a3102 --- /dev/null +++ b/lib/gui/ewindowstyle.cpp @@ -0,0 +1,23 @@ +#include +#include +#include +#include + +DEFINE_REF(eWindowStyleSimple); + +eWindowStyleSimple::eWindowStyleSimple() +{ + m_border_left = m_border_right = m_border_top = m_border_bottom = 10; +} + +void eWindowStyleSimple::handleNewSize(eWindow *wnd, const eSize &size) +{ + eDebug("handle new size: %d x %d", size.width(), size.height()); + + eWidget *child = wnd->child(); + + wnd->m_clip_region = eRect(ePoint(0, 0), size); + + child->move(ePoint(m_border_left, m_border_top)); + child->resize(eSize(size.width() - m_border_left - m_border_right, size.height() - m_border_top - m_border_bottom)); +} diff --git a/lib/gui/ewindowstyle.h b/lib/gui/ewindowstyle.h new file mode 100644 index 00000000..02f155af --- /dev/null +++ b/lib/gui/ewindowstyle.h @@ -0,0 +1,24 @@ +#ifndef __lib_gui_ewindowstyle_h +#define __lib_gui_ewindowstyle_h + +class eWindow; +class eSize; + +#include + +class eWindowStyle: public iObject +{ +public: + virtual void handleNewSize(eWindow *wnd, const eSize &size) = 0; +}; + +class eWindowStyleSimple: public eWindowStyle +{ + DECLARE_REF; +public: + eWindowStyleSimple(); + void handleNewSize(eWindow *wnd, const eSize &size); + int m_border_top, m_border_left, m_border_right, m_border_bottom; +}; + +#endif diff --git a/lib/nav/core.cpp b/lib/nav/core.cpp index 51a02368..72d3fc52 100644 --- a/lib/nav/core.cpp +++ b/lib/nav/core.cpp @@ -1,4 +1,5 @@ #include +#include void eNavigation::serviceEvent(iPlayableService* service, int event) { diff --git a/lib/network/Makefile.am b/lib/network/Makefile.am index cfdc79b1..f5efef9a 100644 --- a/lib/network/Makefile.am +++ b/lib/network/Makefile.am @@ -4,4 +4,6 @@ INCLUDES = \ noinst_LIBRARIES = libenigma_network.a libenigma_network_a_SOURCES = \ - http_dyn.cpp http_file.cpp httpd.cpp serversocket.cpp socket.cpp xmlrpc.cpp + http_dyn.cpp http_file.cpp httpd.cpp serversocket.cpp socket.cpp + +# xmlrpc.cpp diff --git a/lib/network/http_dyn.cpp b/lib/network/http_dyn.cpp index d020133a..eb94d462 100644 --- a/lib/network/http_dyn.cpp +++ b/lib/network/http_dyn.cpp @@ -1,6 +1,6 @@ #include -eHTTPDyn::eHTTPDyn(eHTTPConnection *c, eString result): eHTTPDataSource(c), result(result) +eHTTPDyn::eHTTPDyn(eHTTPConnection *c, std::string result): eHTTPDataSource(c), result(result) { wptr=0; char buffer[10]; @@ -34,18 +34,18 @@ eHTTPDynPathResolver::eHTTPDynPathResolver() #warning autodelete removed } -void eHTTPDynPathResolver::addDyn(eString request, eString path, eString (*function)(eString, eString, eString, eHTTPConnection*)) +void eHTTPDynPathResolver::addDyn(std::string request, std::string path, std::string (*function)(std::string, std::string, std::string, eHTTPConnection*)) { dyn.push_back(new eHTTPDynEntry(request, path, function)); } -eHTTPDataSource *eHTTPDynPathResolver::getDataSource(eString request, eString path, eHTTPConnection *conn) +eHTTPDataSource *eHTTPDynPathResolver::getDataSource(std::string request, std::string path, eHTTPConnection *conn) { - eString p, opt; - if (path.find('?')!=eString::npos) + std::string p, opt; + if (path.find('?')!=std::string::npos) { - p=path.left(path.find('?')); - opt=path.mid(path.find('?')+1); + p=path.substr(0, path.find('?')); + opt=path.substr(path.find('?')+1); } else { p=path; @@ -55,9 +55,9 @@ eHTTPDataSource *eHTTPDynPathResolver::getDataSource(eString request, eString pa if ((i->path==p) && (i->request==request)) { conn->code=-1; - eString s=i->function(request, path, opt, conn); + std::string s=i->function(request, path, opt, conn); - if (s) + if (!s.empty()) return new eHTTPDyn(conn, s); return new eHTTPError(conn, 500); diff --git a/lib/network/http_dyn.h b/lib/network/http_dyn.h index 6fb8b9b1..d714403b 100644 --- a/lib/network/http_dyn.h +++ b/lib/network/http_dyn.h @@ -5,10 +5,10 @@ class eHTTPDyn: public eHTTPDataSource { - eString result; + std::string result; int wptr, size; public: - eHTTPDyn(eHTTPConnection *c, eString result); + eHTTPDyn(eHTTPConnection *c, std::string result); ~eHTTPDyn(); int doWrite(int); }; @@ -17,18 +17,18 @@ class eHTTPDynPathResolver: public eHTTPPathResolver { struct eHTTPDynEntry { - eString request, path; - eString (*function)(eString request, eString path, eString opt, eHTTPConnection *content); + std::string request, path; + std::string (*function)(std::string request, std::string path, std::string opt, eHTTPConnection *content); - eHTTPDynEntry(eString request, eString path, eString (*function)(eString, eString, eString, eHTTPConnection *)): request(request), path(path), function(function) + eHTTPDynEntry(std::string request, std::string path, std::string (*function)(std::string, std::string, std::string, eHTTPConnection *)): request(request), path(path), function(function) { } }; ePtrList dyn; public: - void addDyn(eString request, eString path, eString (*function)(eString, eString, eString, eHTTPConnection *conn)); + void addDyn(std::string request, std::string path, std::string (*function)(std::string, std::string, std::string, eHTTPConnection *conn)); eHTTPDynPathResolver(); - eHTTPDataSource *getDataSource(eString request, eString path, eHTTPConnection *conn); + eHTTPDataSource *getDataSource(std::string request, std::string path, eHTTPConnection *conn); }; #endif diff --git a/lib/network/http_file.cpp b/lib/network/http_file.cpp index 19c8a15f..2b47d63c 100644 --- a/lib/network/http_file.cpp +++ b/lib/network/http_file.cpp @@ -64,7 +64,7 @@ eHTTPFilePathResolver::eHTTPFilePathResolver() static char _base64[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; -static int unbase64(eString &dst, const eString string) +static int unbase64(std::string &dst, const std::string string) { dst=""; char c[4]; @@ -124,21 +124,21 @@ int CheckUnixPassword(const char *user, const char *pass) return !!strcmp(cres, cpwd); } -static int checkAuth(const eString cauth) +static int checkAuth(const std::string cauth) { - eString auth; - if (cauth.left(6) != "Basic ") + std::string auth; + if (cauth.substr(0, 6) != "Basic ") return -1; - if (unbase64(auth, cauth.mid(6))) + if (unbase64(auth, cauth.substr(6))) return -1; - eString username=auth.left(auth.find(":")); - eString password=auth.mid(auth.find(":")+1); + std::string username=auth.substr(0, auth.find(":")); + std::string password=auth.substr(auth.find(":")+1); if (CheckUnixPassword(username.c_str(), password.c_str())) return -1; return 0; } -eHTTPDataSource *eHTTPFilePathResolver::getDataSource(eString request, eString path, eHTTPConnection *conn) +eHTTPDataSource *eHTTPFilePathResolver::getDataSource(std::string request, std::string path, eHTTPConnection *conn) { int method; eDebug("request = %s, path = %s", request.c_str(), path.c_str()); @@ -148,7 +148,7 @@ eHTTPDataSource *eHTTPFilePathResolver::getDataSource(eString request, eString p method=eHTTPFile::methodPUT; else return new eHTTPError(conn, 405); // method not allowed - if (path.find("../")!=eString::npos) // evil hax0r + if (path.find("../")!=std::string::npos) // evil hax0r return new eHTTPError(conn, 403); if (path[0] != '/') // prepend '/' path.insert(0,"/"); @@ -158,11 +158,11 @@ eHTTPDataSource *eHTTPFilePathResolver::getDataSource(eString request, eString p eHTTPDataSource *data=0; for (ePtrList::iterator i(translate); i != translate.end(); ++i) { - if (i->root==path.left(i->root.length())) + if (i->root==path.substr(0, i->root.length())) { - eString newpath=i->path+path.mid(i->root.length()); + std::string newpath=i->path+path.substr(i->root.length()); if (newpath.find('?')) - newpath=newpath.left(newpath.find('?')); + newpath=newpath.substr(0, newpath.find('?')); eDebug("translated %s to %s", path.c_str(), newpath.c_str()); if (i->authorized & ((method==eHTTPFile::methodGET)?1:2)) @@ -194,7 +194,7 @@ eHTTPDataSource *eHTTPFilePathResolver::getDataSource(eString request, eString p break; } - eString ext=path.mid(path.rfind('.')); + std::string ext=path.substr(path.rfind('.')); const char *mime="text/unknown"; if ((ext==".html") || (ext==".htm")) mime="text/html"; @@ -218,7 +218,7 @@ eHTTPDataSource *eHTTPFilePathResolver::getDataSource(eString request, eString p return data; } -void eHTTPFilePathResolver::addTranslation(eString path, eString root, int authorized) +void eHTTPFilePathResolver::addTranslation(std::string path, std::string root, int authorized) { if (path[path.length()-1]!='/') path+='/'; diff --git a/lib/network/http_file.h b/lib/network/http_file.h index 88bffc60..109dc07e 100644 --- a/lib/network/http_file.h +++ b/lib/network/http_file.h @@ -20,18 +20,18 @@ class eHTTPFilePathResolver: public eHTTPPathResolver { struct eHTTPFilePath { - eString path; - eString root; + std::string path; + std::string root; int authorized; // must be authorized (1 means read, 2 write) - eHTTPFilePath(eString path, eString root, int authorized): path(path), root(root), authorized(authorized) + eHTTPFilePath(std::string path, std::string root, int authorized): path(path), root(root), authorized(authorized) { } }; ePtrList translate; public: eHTTPFilePathResolver(); - eHTTPDataSource *getDataSource(eString request, eString path, eHTTPConnection *conn); - void addTranslation(eString path, eString root, int auth); + eHTTPDataSource *getDataSource(std::string request, std::string path, eHTTPConnection *conn); + void addTranslation(std::string path, std::string root, int auth); }; #endif diff --git a/lib/network/httpd.cpp b/lib/network/httpd.cpp index acd3ebe6..f706ccf8 100644 --- a/lib/network/httpd.cpp +++ b/lib/network/httpd.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -26,7 +27,7 @@ int eHTTPDataSource::doWrite(int) eHTTPError::eHTTPError(eHTTPConnection *c, int errcode): eHTTPDataSource(c), errcode(errcode) { - eString error="unknown error"; + std::string error="unknown error"; switch (errcode) { case 400: error="Bad Request"; break; @@ -44,9 +45,9 @@ eHTTPError::eHTTPError(eHTTPConnection *c, int errcode): eHTTPDataSource(c), err int eHTTPError::doWrite(int w) { - eString html; - html+="Error "+eString().setNum(connection->code)+""+ - "

Error "+eString().setNum(errcode)+": "+connection->code_descr+"

\n"; + std::string html; + html+="Error " + getNum(connection->code) + ""+ + "

Error " + getNum(errcode) + ": " + connection->code_descr + "

\n"; connection->writeBlock(html.c_str(), html.length()); return -1; } @@ -266,7 +267,7 @@ int eHTTPConnection::processLocalState() #ifdef DEBUG_HTTPD eDebug("local request"); #endif - eString req=request+" "+requestpath+" "+httpversion+"\r\n"; + std::string req=request+" "+requestpath+" "+httpversion+"\r\n"; writeBlock(req.c_str(), req.length()); localstate=stateHeader; remotestate=stateResponse; @@ -277,7 +278,7 @@ int eHTTPConnection::processLocalState() #ifdef DEBUG_HTTPD eDebug("local Response"); #endif - writeString( (httpversion + " " + eString().setNum(code)+" " + code_descr + "\r\n").c_str() ); + writeString( (httpversion + " " + getNum(code) + " " + code_descr + "\r\n").c_str() ); localstate=stateHeader; local_header["Connection"]="close"; break; @@ -323,7 +324,7 @@ int eHTTPConnection::processLocalState() // move to stateClose if (remote_header.find("Connection") != remote_header.end()) { - eString &connection=remote_header["Connection"]; + std::string &connection=remote_header["Connection"]; if (connection == "keep-alive") localstate=stateWait; else @@ -387,7 +388,7 @@ int eHTTPConnection::processRemoteState() #ifdef DEBUG_HTTPD eDebug("stateRequest"); #endif - eString line; + std::string line; if (!getLine(line)) { done=1; @@ -412,16 +413,16 @@ int eHTTPConnection::processRemoteState() return -1; break; } - request=line.left(del[0]); - requestpath=line.mid(del[0]+1, (del[1]==-1)?-1:(del[1]-del[0]-1)); + request=line.substr(0, del[0]); + requestpath=line.substr(del[0]+1, (del[1]==-1)?-1:(del[1]-del[0]-1)); if (del[1]!=-1) { is09=0; - httpversion=line.mid(del[1]+1); + httpversion=line.substr(del[1]+1); } else is09=1; - if (is09 || (httpversion.left(7) != "HTTP/1.") || httpversion.size()!=8) + if (is09 || (httpversion.substr(0, 7) != "HTTP/1.") || httpversion.size()!=8) { remotestate=stateData; done=0; @@ -437,7 +438,7 @@ int eHTTPConnection::processRemoteState() #ifdef DEBUG_HTTPD eDebug("state response.."); #endif - eString line; + std::string line; if (!getLine(line)) { done=1; @@ -454,10 +455,10 @@ int eHTTPConnection::processRemoteState() code=-1; else { - httpversion=line.left(del[0]); - code=atoi(line.mid(del[0]+1, (del[1]==-1)?-1:(del[1]-del[0]-1)).c_str()); + httpversion=line.substr(0, del[0]); + code=atoi(line.substr(del[0]+1, (del[1]==-1)?-1:(del[1]-del[0]-1)).c_str()); if (del[1] != -1) - code_descr=line.mid(del[1]+1); + code_descr=line.substr(del[1]+1); else code_descr=""; } @@ -470,7 +471,7 @@ int eHTTPConnection::processRemoteState() #ifdef DEBUG_HTTPD eDebug("remote stateHeader"); #endif - eString line; + std::string line; if (!getLine(line)) { done=1; @@ -519,9 +520,9 @@ int eHTTPConnection::processRemoteState() } else { int del=line.find(":"); - eString name=line.left(del), value=line.mid(del+1); + std::string name=line.substr(0, del), value=line.substr(del+1); if (value[0]==' ') - value=value.mid(1); + value=value.substr(1); remote_header[std::string(name)]=std::string(value); } done=1; @@ -583,7 +584,7 @@ void eHTTPConnection::writeString(const char *data) writeBlock(data, strlen(data)); } -int eHTTPConnection::getLine(eString &line) +int eHTTPConnection::getLine(std::string &line) { if (!canReadLine()) return 0; diff --git a/lib/network/httpd.h b/lib/network/httpd.h index 791d49c8..61fe2c75 100644 --- a/lib/network/httpd.h +++ b/lib/network/httpd.h @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include #include @@ -19,7 +19,7 @@ class eHTTPPathResolver { public: virtual ~eHTTPPathResolver() {}; - virtual eHTTPDataSource *getDataSource(eString request, eString path, eHTTPConnection *conn)=0; + virtual eHTTPDataSource *getDataSource(std::string request, std::string path, eHTTPConnection *conn)=0; }; class eHTTPDataSource @@ -47,7 +47,7 @@ class eHTTPConnection: public eSocket { void doError(int error); - int getLine(eString &line); + int getLine(std::string &line); int processLocalState(); int processRemoteState(); @@ -93,13 +93,13 @@ public: ~eHTTPConnection(); // stateRequest - eString request, requestpath, httpversion; + std::string request, requestpath, httpversion; int is09; // stateResponse int code; - eString code_descr; + std::string code_descr; std::map remote_header, local_header; diff --git a/lib/network/serversocket.lo b/lib/network/serversocket.lo index 8039034b..180ed5dc 100644 Binary files a/lib/network/serversocket.lo and b/lib/network/serversocket.lo differ diff --git a/lib/network/socket.cpp b/lib/network/socket.cpp index 9de0ca0a..628a128b 100644 --- a/lib/network/socket.cpp +++ b/lib/network/socket.cpp @@ -43,16 +43,16 @@ void eSocket::inject(const char *data, int len) readyRead_(); } -eString eSocket::readLine() +std::string eSocket::readLine() { int size=readbuffer.searchchr('\n'); if (size == -1) - return eString(); + return std::string(); size++; // ich will auch das \n char buffer[size+1]; buffer[size]=0; readbuffer.read(buffer, size); - return eString(buffer); + return std::string(buffer); } bool eSocket::canReadLine() @@ -225,7 +225,7 @@ int eSocket::getDescriptor() return socketdesc; } -int eSocket::connectToHost(eString hostname, int port) +int eSocket::connectToHost(std::string hostname, int port) { struct hostent *server; int res; diff --git a/lib/network/socket.h b/lib/network/socket.h index edf9b904..08a191f6 100644 --- a/lib/network/socket.h +++ b/lib/network/socket.h @@ -10,7 +10,7 @@ #include #include -#include +#include #include #include @@ -32,7 +32,7 @@ public: eSocket(eMainloop *ml); eSocket(int socket, int issocket, eMainloop *ml); ~eSocket(); - int connectToHost(eString hostname, int port); + int connectToHost(std::string hostname, int port); int getDescriptor(); int writeBlock(const char *data, unsigned int len); int setSocket(int socketfd, int issocket, eMainloop *ml); @@ -40,7 +40,7 @@ public: int readBlock(char *data, unsigned int maxlen); int bytesAvailable(); bool canReadLine(); - eString readLine(); + std::string readLine(); void close(); // flow control: start/stop data delivery into read buffer. void enableRead(); diff --git a/lib/network/socket.lo b/lib/network/socket.lo index 1d809469..912fce9e 100644 Binary files a/lib/network/socket.lo and b/lib/network/socket.lo differ diff --git a/lib/network/xmlrpc.cpp b/lib/network/xmlrpc.cpp index 57b09e82..3d981d51 100644 --- a/lib/network/xmlrpc.cpp +++ b/lib/network/xmlrpc.cpp @@ -1,9 +1,10 @@ #ifndef DISABLE_NETWORK #include +#include -static std::map&, ePtrList&)> rpcproc; +static std::map&, ePtrList&)> rpcproc; void eXMLRPCVariant::zero() { @@ -17,7 +18,7 @@ void eXMLRPCVariant::zero() // _base64=0; } -eXMLRPCVariant::eXMLRPCVariant(std::map *__struct) +eXMLRPCVariant::eXMLRPCVariant(std::map *__struct) { zero(); _struct=__struct; @@ -41,7 +42,7 @@ eXMLRPCVariant::eXMLRPCVariant(bool *__boolean) _boolean=__boolean; } -eXMLRPCVariant::eXMLRPCVariant(eString *__string) +eXMLRPCVariant::eXMLRPCVariant(std::string *__string) { zero(); _string=__string; @@ -73,15 +74,15 @@ eXMLRPCVariant::eXMLRPCVariant(const eXMLRPCVariant &c) if (c._boolean) _boolean=new bool(*c._boolean); if (c._string) - _string=new eString(*c._string); + _string=new std::string(*c._string); if (c._double) _double=new double(*c._double); // datetime, base64 if (c._struct) { - _struct=new std::map; - for (std::map::iterator b(c._struct->begin()); b != c._struct->end(); ++b) - _struct->insert(std::pair(b->first, new eXMLRPCVariant(*b->second))); + _struct=new std::map; + for (std::map::iterator b(c._struct->begin()); b != c._struct->end(); ++b) + _struct->insert(std::pair(b->first, new eXMLRPCVariant(*b->second))); } if (c._array) _array = new std::vector(*c._array); @@ -91,7 +92,7 @@ eXMLRPCVariant::~eXMLRPCVariant() { if (_struct) { - for (std::map::iterator i(_struct->begin()); i != _struct->end(); ++i) + for (std::map::iterator i(_struct->begin()); i != _struct->end(); ++i) delete i->second; delete _struct; @@ -112,7 +113,7 @@ eXMLRPCVariant::~eXMLRPCVariant() delete _base64;*/ } -std::map *eXMLRPCVariant::getStruct() +std::map *eXMLRPCVariant::getStruct() { return _struct; } @@ -132,7 +133,7 @@ bool *eXMLRPCVariant::getBoolean() return _boolean; } -eString *eXMLRPCVariant::getString() +std::string *eXMLRPCVariant::getString() { return _string; } @@ -152,61 +153,62 @@ double *eXMLRPCVariant::getDouble() return _base64; } */ -void eXMLRPCVariant::toXML(eString &result) +void eXMLRPCVariant::toXML(std::string &result) { if (getArray()) { - static eString s1(""); + static std::string s1(""); result+=s1; for (unsigned int i=0; isize(); i++) { - static eString s(" "); + static std::string s(" "); result+=s; (*getArray())[i].toXML(result); - static eString s1("\n"); + static std::string s1("\n"); result+=s1; } - static eString s2("\n"); + static std::string s2("\n"); result+=s2; } else if (getStruct()) { - static eString s1(""); + static std::string s1(""); result+=s1; - for (std::map::iterator i(_struct->begin()); i != _struct->end(); ++i) + for (std::map::iterator i(_struct->begin()); i != _struct->end(); ++i) { - static eString s1(" "); + static std::string s1(" "); result+=s1; result+=i->first; - static eString s2(""); + static std::string s2(""); result+=s2; i->second->toXML(result); - static eString s3("\n"); + static std::string s3("\n"); result+=s3; } - static eString s2("\n"); + static std::string s2("\n"); result+=s2; } else if (getI4()) { - static eString s1(""); + static std::string s1(""); result+=s1; - result+=eString().setNum(*getI4()); - static eString s2(""); + result+=getNum(*getI4()); + static std::string s2(""); result+=s2; } else if (getBoolean()) { - static eString s0("0"); - static eString s1("1"); + static std::string s0("0"); + static std::string s1("1"); result+=(*getBoolean())?s1:s0; } else if (getString()) { - static eString s1(""); - static eString s2(""); + static std::string s1(""); + static std::string s2(""); result+=s1; result+=*getString(); result+=s2; } else if (getDouble()) { - result+=eString().sprintf("%lf", *getDouble()); +// result+=std::string().sprintf("%lf", *getDouble()); +#warning double support removed } else eFatal("couldn't append"); } @@ -224,11 +226,11 @@ static eXMLRPCVariant *fromXML(XMLTreeNode *n) else if (!strcmp(n->GetType(), "boolean")) return new eXMLRPCVariant(new bool(atoi(data))); else if (!strcmp(n->GetType(), "string")) - return new eXMLRPCVariant(new eString(data)); + return new eXMLRPCVariant(new std::string(data)); else if (!strcmp(n->GetType(), "double")) return new eXMLRPCVariant(new double(atof(data))); else if (!strcmp(n->GetType(), "struct")) { - std::map *s=new std::map; + std::map *s=new std::map; for (n=n->GetChild(); n; n=n->GetNext()) { if (strcmp(data, "member")) @@ -236,12 +238,12 @@ static eXMLRPCVariant *fromXML(XMLTreeNode *n) delete s; return 0; } - eString name=0; + std::string name=0; eXMLRPCVariant *value; for (XMLTreeNode *v=n->GetChild(); v; v=v->GetNext()) { if (!strcmp(v->GetType(), "name")) - name=eString(v->GetData()); + name=std::string(v->GetData()); else if (!strcmp(v->GetType(), "value")) value=fromXML(v); } @@ -292,7 +294,7 @@ int eXMLRPCResponse::doCall() eDebug("doing call"); result=""; // get method name - eString methodName=0; + std::string methodName=0; if (connection->remote_header["Content-Type"]!="text/xml") { @@ -319,7 +321,7 @@ int eXMLRPCResponse::doCall() for (XMLTreeNode *c=methodCall->GetChild(); c; c=c->GetNext()) { if (!strcmp(c->GetType(), "methodName")) - methodName=eString(c->GetData()); + methodName=std::string(c->GetData()); else if (!strcmp(c->GetType(), "params")) { for (XMLTreeNode *p=c->GetChild(); p; p=p->GetNext()) @@ -441,24 +443,24 @@ void xmlrpc_initialize(eHTTPD *httpd) httpd->addResolver(new eHTTPXMLRPCResolver); } -void xmlrpc_addMethod(eString methodName, int (*proc)(std::vector&, ePtrList&)) +void xmlrpc_addMethod(std::string methodName, int (*proc)(std::vector&, ePtrList&)) { rpcproc[methodName]=proc; } -void xmlrpc_fault(ePtrList &res, int faultCode, eString faultString) +void xmlrpc_fault(ePtrList &res, int faultCode, std::string faultString) { - std::map *s=new std::map; + std::map *s=new std::map; s->INSERT("faultCode", new eXMLRPCVariant(new __s32(faultCode))); - s->INSERT("faultString", new eXMLRPCVariant(new eString(faultString))); + s->INSERT("faultString", new eXMLRPCVariant(new std::string(faultString))); res.push_back(new eXMLRPCVariant(s)); } -int xmlrpc_checkArgs(eString args, std::vector &parm, ePtrList &res) +int xmlrpc_checkArgs(std::string args, std::vector &parm, ePtrList &res) { if (parm.size() != args.length()) { - xmlrpc_fault(res, -500, eString().sprintf("parameter count mismatch (found %d, expected %d)", parm.size(), args.length())); + xmlrpc_fault(res, -500, std::string().sprintf("parameter count mismatch (found %d, expected %d)", parm.size(), args.length())); return 1; } @@ -499,7 +501,7 @@ int xmlrpc_checkArgs(eString args, std::vector &parm, ePtrList #include -#include +#include #include #include -#define INSERT(KEY,VALUE) insert(std::pair(KEY,VALUE)) +#define INSERT(KEY,VALUE) insert(std::pair(KEY,VALUE)) class eXMLRPCVariant { - std::map *_struct; + std::map *_struct; std::vector *_array; __s32 *_i4; bool *_boolean; - eString *_string; + std::string *_string; double *_double; // QDateTime *_datetime; // QByteArray *_base64; void zero(); public: - eXMLRPCVariant(std::map *_struct); + eXMLRPCVariant(std::map *_struct); eXMLRPCVariant(std::vector *_array); eXMLRPCVariant(__s32 *_i4); eXMLRPCVariant(bool *_boolean); - eXMLRPCVariant(eString *_string); + eXMLRPCVariant(std::string *_string); eXMLRPCVariant(double *_double); // eXMLRPCVariant(QDateTime *_datetime); // eXMLRPCVariant(QByteArray *_base64); eXMLRPCVariant(const eXMLRPCVariant &c); ~eXMLRPCVariant(); - std::map *getStruct(); + std::map *getStruct(); std::vector *getArray(); __s32 *getI4(); bool *getBoolean(); - eString *getString(); + std::string *getString(); double *getDouble(); // QDateTime *getDatetime(); // QByteArray *getBase64(); - void toXML(eString &); + void toXML(std::string &); }; class eXMLRPCResponse: public eHTTPDataSource { XMLTreeParser parser; - eString result; + std::string result; int size; int wptr; int doCall(); @@ -65,15 +65,15 @@ public: }; void xmlrpc_initialize(eHTTPD *httpd); -void xmlrpc_addMethod(eString methodName, int (*)(std::vector&, ePtrList&)); -void xmlrpc_fault(ePtrList &res, int faultCode, eString faultString); -int xmlrpc_checkArgs(eString args, std::vector&, ePtrList &res); +void xmlrpc_addMethod(std::string methodName, int (*)(std::vector&, ePtrList&)); +void xmlrpc_fault(ePtrList &res, int faultCode, std::string faultString); +int xmlrpc_checkArgs(std::string args, std::vector&, ePtrList &res); class eHTTPXMLRPCResolver: public eHTTPPathResolver { public: eHTTPXMLRPCResolver(); - eHTTPDataSource *getDataSource(eString request, eString path, eHTTPConnection *conn); + eHTTPDataSource *getDataSource(std::string request, std::string path, eHTTPConnection *conn); }; #endif diff --git a/lib/python/Makefile.am b/lib/python/Makefile.am new file mode 100644 index 00000000..c3d98c0b --- /dev/null +++ b/lib/python/Makefile.am @@ -0,0 +1,12 @@ +INCLUDES = \ + -I$(top_srcdir)/include \ + -I$(top_srcdir)/src \ + -I/usr/include/python2.3 + +noinst_LIBRARIES = libenigma_python.a + +libenigma_python_a_SOURCES = \ + python.cpp enigma_python_wrap.cxx + +enigma_python_wrap.cxx: enigma_python.i + swig -I$(top_srcdir)/ -c++ -python enigma_python.i diff --git a/lib/python/enigma_python.i b/lib/python/enigma_python.i new file mode 100644 index 00000000..67244f10 --- /dev/null +++ b/lib/python/enigma_python.i @@ -0,0 +1,23 @@ +%module enigma +%{ +#define SWIG_COMPILE +#include +#include +#include +#include +#include +%} + +#define DEBUG +%include "stl.i" +%include +%include +%include +%include +%include +%include +%template(eServiceCenterPtr) ePtr; +%template(iPlayableServicePtr) ePtr; +%template(iPauseableServicePtr) ePtr; +%template(iRecordableServicePtr) ePtr; +%template(iListableServicePtr) ePtr; diff --git a/lib/python/python.cpp b/lib/python/python.cpp new file mode 100644 index 00000000..a9ad32f6 --- /dev/null +++ b/lib/python/python.cpp @@ -0,0 +1,57 @@ +#include +#include + +extern "C" void init_enigma(); + +ePython::ePython() +{ + Py_Initialize(); + + init_enigma(); +} + +ePython::~ePython() +{ + Py_Finalize(); +} + +int ePython::execute(const std::string &pythonfile, const std::string &funcname) +{ + PyObject *pName, *pModule, *pDict, *pFunc, *pArgs, *pValue; + + pName = PyString_FromString(pythonfile.c_str()); + + pModule = PyImport_Import(pName); + Py_DECREF(pName); + + if (pModule != NULL) + { + pDict = PyModule_GetDict(pModule); + + pFunc = PyDict_GetItemString(pDict, funcname.c_str()); + + if (pFunc && PyCallable_Check(pFunc)) + { + pArgs = PyTuple_New(0); + // implement arguments.. + pValue = PyObject_CallObject(pFunc, pArgs); + Py_DECREF(pArgs); + if (pValue != NULL) + { + printf("Result of call: %ld\n", PyInt_AsLong(pValue)); + Py_DECREF(pValue); + } else + { + Py_DECREF(pModule); + PyErr_Print(); + return 1; + } + } + } else + { + if (PyErr_Occurred()) + PyErr_Print(); + return 1; + } + return 0; +} diff --git a/lib/python/python.h b/lib/python/python.h new file mode 100644 index 00000000..bde18146 --- /dev/null +++ b/lib/python/python.h @@ -0,0 +1,16 @@ +#ifndef __lib_python_python_h +#define __lib_python_python_h + +#include + +class ePython +{ +public: + ePython(); + ~ePython(); + int execute(const std::string &pythonfile, const std::string &funcname); +private: + +}; + +#endif diff --git a/lib/service/iservice.h b/lib/service/iservice.h index 253f8c3b..a6369574 100644 --- a/lib/service/iservice.h +++ b/lib/service/iservice.h @@ -2,7 +2,7 @@ #define __lib_dvb_iservice_h #include -#include +#include #include #include @@ -41,7 +41,7 @@ public: inline int getSortKey() const { return (flags & hasSortKey) ? data[3] : ((flags & sort1) ? 1 : 0); } int data[8]; - eString path; + std::string path; eServiceReference() : type(idInvalid), flags(0) @@ -93,13 +93,13 @@ public: data[3]=data3; data[4]=data4; } - eServiceReference(int type, int flags, const eString &path) + eServiceReference(int type, int flags, const std::string &path) : type(type), flags(flags), path(path) { memset(data, 0, sizeof(data)); } - eServiceReference(const eString &string); - eString toString() const; + eServiceReference(const std::string &string); + std::string toString() const; bool operator==(const eServiceReference &c) const { if (type != c.type) @@ -137,9 +137,11 @@ public: class iServiceInformation: public iObject { public: - virtual RESULT getName(eString &name)=0; + virtual RESULT getName(std::string &name)=0; }; +typedef ePtr iServiceInformationPtr; + class iPauseableService: public iObject { public: @@ -147,6 +149,8 @@ public: virtual RESULT unpause()=0; }; +typedef ePtr iPauseableServicePtr; + class iPlayableService: public iObject { friend class iServiceHandler; @@ -163,6 +167,8 @@ public: virtual RESULT getIServiceInformation(ePtr &ptr)=0; }; +typedef ePtr iPlayableServicePtr; + class iRecordableService: public iObject { public: @@ -170,12 +176,16 @@ public: virtual RESULT stop()=0; }; +typedef ePtr iRecordableServicePtr; + class iListableService: public iObject { public: virtual RESULT getContent(std::list &list)=0; }; +typedef ePtr iListableServicePtr; + class iServiceHandler: public iObject { public: @@ -184,4 +194,6 @@ public: virtual RESULT list(const eServiceReference &, ePtr &ptr)=0; }; +typedef ePtr iServiceHandlerPtr; + #endif diff --git a/lib/service/service.cpp b/lib/service/service.cpp index 8abf883f..d18b8eee 100644 --- a/lib/service/service.cpp +++ b/lib/service/service.cpp @@ -1,8 +1,10 @@ +#include +#include #include #include #include -eServiceReference::eServiceReference(const eString &string) +eServiceReference::eServiceReference(const std::string &string) { const char *c=string.c_str(); int pathl=-1; @@ -18,13 +20,16 @@ eServiceReference::eServiceReference(const eString &string) path=c+pathl; } -eString eServiceReference::toString() const +std::string eServiceReference::toString() const { - eString ret; - ret+=eString().sprintf("%d:", type); - ret+=eString().sprintf("%d", flags); + std::string ret; + ret += getNum(type); + ret += ":"; + ret += getNum(flags); for (unsigned int i=0; i #include +class eServiceCenter; + +typedef ePtr eServiceCenterPtr; + class eServiceCenter: public iServiceHandler { DECLARE_REF; private: - std::map > handler; + std::map handler; static eServiceCenter *instance; public: eServiceCenter(); virtual ~eServiceCenter(); // iServiceHandler - RESULT play(const eServiceReference &, ePtr &ptr); - RESULT record(const eServiceReference &, ePtr &ptr); - RESULT list(const eServiceReference &, ePtr &ptr); + RESULT play(const eServiceReference &, iPlayableServicePtr &ptr); + RESULT record(const eServiceReference &, iRecordableServicePtr &ptr); + RESULT list(const eServiceReference &, iListableServicePtr &ptr); // eServiceCenter - static RESULT getInstance(ePtr &ptr) { ptr = instance; return 0; } + static RESULT getInstance(eServiceCenterPtr &ptr) { ptr = instance; return 0; } RESULT addServiceFactory(int id, iServiceHandler *hnd); RESULT removeServiceFactory(int id); }; diff --git a/lib/service/servicedvb.cpp b/lib/service/servicedvb.cpp index cbf9a706..3b22ab7b 100644 --- a/lib/service/servicedvb.cpp +++ b/lib/service/servicedvb.cpp @@ -158,7 +158,7 @@ RESULT eDVBServicePlay::getIServiceInformation(ePtr &ptr) return 0; } -RESULT eDVBServicePlay::getName(eString &name) +RESULT eDVBServicePlay::getName(std::string &name) { name = "DVB service"; return 0; diff --git a/lib/service/servicedvb.h b/lib/service/servicedvb.h index 6e901483..42ca30f7 100644 --- a/lib/service/servicedvb.h +++ b/lib/service/servicedvb.h @@ -45,7 +45,7 @@ public: RESULT getIServiceInformation(ePtr &ptr); // iServiceInformation - RESULT getName(eString &name); + RESULT getName(std::string &name); }; #endif diff --git a/lib/service/servicefs.cpp b/lib/service/servicefs.cpp index 4bdc11a9..f4a9b737 100644 --- a/lib/service/servicefs.cpp +++ b/lib/service/servicefs.cpp @@ -74,7 +74,7 @@ RESULT eServiceFS::getContent(std::list &list) if (!(strcmp(e->d_name, ".") && strcmp(e->d_name, ".."))) continue; - eString filename; + std::string filename; filename = path; filename += e->d_name; diff --git a/lib/service/servicefs.h b/lib/service/servicefs.h index f98cbc4c..7e66ba21 100644 --- a/lib/service/servicefs.h +++ b/lib/service/servicefs.h @@ -21,7 +21,7 @@ class eServiceFS: public iListableService { DECLARE_REF; private: - eString path; + std::string path; friend class eServiceFactoryFS; eServiceFS(const char *path); public: diff --git a/lib/service/servicemp3.cpp b/lib/service/servicemp3.cpp index 105ffbfa..d1c9001d 100644 --- a/lib/service/servicemp3.cpp +++ b/lib/service/servicemp3.cpp @@ -113,7 +113,7 @@ RESULT eServiceMP3::unpause() { printf("mp3 unpauses!\n"); return 0; } RESULT eServiceMP3::getIServiceInformation(ePtr&i) { i = this; return 0; } -RESULT eServiceMP3::getName(eString &name) +RESULT eServiceMP3::getName(std::string &name) { name = "MP3 File: " + filename; return 0; diff --git a/lib/service/servicemp3.h b/lib/service/servicemp3.h index 940e141d..cfca4242 100644 --- a/lib/service/servicemp3.h +++ b/lib/service/servicemp3.h @@ -48,7 +48,7 @@ public: RESULT getIServiceInformation(ePtr&); // iServiceInformation - RESULT getName(eString &name); + RESULT getName(std::string &name); }; #endif diff --git a/main/Makefile.am b/main/Makefile.am index ff99797d..6b0fb416 100644 --- a/main/Makefile.am +++ b/main/Makefile.am @@ -14,6 +14,7 @@ enigma2_LDADD_WHOLE = \ $(top_builddir)/lib/dvb_si/libenigma_dvb_si.a \ $(top_builddir)/lib/gdi/libenigma_gdi.a \ $(top_builddir)/lib/gui/libenigma_gui.a \ + $(top_builddir)/lib/python/libenigma_python.a \ $(top_builddir)/lib/nav/libenigma_nav.a \ $(top_builddir)/lib/network/libenigma_network.a \ $(top_builddir)/lib/service/libenigma_service.a @@ -25,7 +26,7 @@ enigma2_LDADD = \ @MAD_LIBS@ \ @PNG_LIBS@ \ @SIGC_LIBS@ \ - -ldl -lpthread -lcrypt -lresolv + -ldl -lpthread -lcrypt -lresolv -lpython2.3 enigma2$(EXEEXT): $(enigma2_OBJECTS) $(enigma2_DEPENDENCIES) $(enigma2_LDADD_WHOLE) @rm -f enigma2$(EXEEXT) diff --git a/main/enigma-playlist.cpp b/main/enigma-playlist.cpp index 43dcb1d9..bafefe9a 100644 --- a/main/enigma-playlist.cpp +++ b/main/enigma-playlist.cpp @@ -112,7 +112,7 @@ public: eDebug("failed to get iserviceinformation"); break; } - eString name; + std::string name; m_serviceInformation->getName(name); eDebug("NEW running service: %s", name.c_str()); break; diff --git a/main/enigma.cpp b/main/enigma.cpp index dd9084a2..81391c32 100644 --- a/main/enigma.cpp +++ b/main/enigma.cpp @@ -17,6 +17,8 @@ #include +#include + #ifdef OBJECT_DEBUG int object_total_remaining; @@ -50,10 +52,12 @@ int main() #ifdef OBJECT_DEBUG atexit(object_dump); #endif - eInit init; - + init.setRunlevel(eAutoInitNumbers::main); + + // gui stuff +#if 0 ePtr my_dc; gFBDC::getInstance(my_dc); #if 1 @@ -164,5 +168,13 @@ int main() // dumpRegion(dsk.m_dirty_region); dsk.paint(); + +#endif + + ePython python; + + printf("about to execute TEST :)\n"); + python.execute("mytest", "test"); + return 0; } diff --git a/mytest.py b/mytest.py new file mode 100644 index 00000000..5a9d4c84 --- /dev/null +++ b/mytest.py @@ -0,0 +1,26 @@ +from enigma import * + +def test(): + ref = eServiceReference("4097:47:0:0:0:0:0:0:0:0:/sine_60s_100.mp3"); + + sc = eServiceCenterPtr() + print sc + + if eServiceCenter.getInstance(sc): + print "no eServiceCenter instance!" + else: + print "now trying to play!" + i = iPlayableServicePtr(); + if sc.play(ref, i): + print "play failed! :(" + else: + print "play ruled!" + + p = iPauseableServicePtr() + if (i.getIPausableService(p)): + print "no pause available" + else: + p.pause() + p.unpause() + + return 0