Skip to content

Commit

Permalink
Merge pull request #3463 from jimfcarroll/cleanup-control
Browse files Browse the repository at this point in the history
Cleanup XBMCAddon::xbmcgui::Control class and related docs
  • Loading branch information
Jim Carroll committed Oct 21, 2013
2 parents 96410e2 + 395e4cd commit 1ae84d9
Show file tree
Hide file tree
Showing 57 changed files with 768 additions and 908 deletions.
2 changes: 1 addition & 1 deletion codegenerator.mk
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ GENERATE_DEPS += $(TOPDIR)/xbmc/interfaces/legacy/*.h $(TOPDIR)/xbmc/interfaces/
vpath %.i $(INTERFACES_DIR)/swig

$(GENDIR)/%.cpp: $(GENDIR)/%.xml $(JAVA) $(SWIG) $(DOXY_XML_PATH)
$(JAVA) -cp "$(GROOVY_DIR)/groovy-all-1.8.9.jar:$(GROOVY_DIR)/commons-lang-2.6.jar:$(TOPDIR)/tools/codegenerator:$(INTERFACES_DIR)/python" \
$(JAVA) -cp "$(GROOVY_DIR)/groovy-all-2.1.7.jar:$(GROOVY_DIR)/commons-lang-2.6.jar:$(TOPDIR)/tools/codegenerator:$(INTERFACES_DIR)/python" \
groovy.ui.GroovyMain $(TOPDIR)/tools/codegenerator/Generator.groovy $< $(INTERFACES_DIR)/python/PythonSwig.cpp.template $@ $(DOXY_XML_PATH)
rm $<

Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion tools/codegenerator/GenerateSWIGBindings.bat
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ rem run doxygen
rem run swig to generate the XML used by groovy to generate the python bindings
"%bin_dir%\swig\swig.exe" -w401 -c++ -outdir "%python_generated_dir%" -o "%python_generated_dir%\%2.xml" -xml -I"%base_Dir%\xbmc" -xmllang python "%swig_dir%\%2.i"
rem run groovy to generate the python bindings
java.exe -cp "%groovy_dir%\groovy-all-1.8.9.jar;%groovy_dir%\commons-lang-2.6.jar;%generator_dir%;%python_dir%" groovy.ui.GroovyMain "%generator_dir%\Generator.groovy" "%python_generated_dir%\%2.xml" "%python_dir%\PythonSwig.cpp.template" "%python_generated_dir%\%2.cpp" "%doxygen_dir%"
java.exe -cp "%groovy_dir%\groovy-all-2.1.7.jar;%groovy_dir%\commons-lang-2.6.jar;%generator_dir%;%python_dir%" groovy.ui.GroovyMain "%generator_dir%\Generator.groovy" "%python_generated_dir%\%2.xml" "%python_dir%\PythonSwig.cpp.template" "%python_generated_dir%\%2.cpp" "%doxygen_dir%"

rem delete the XML file generated by SWIG as it's not needed anymore
del "%python_generated_dir%\%2.xml" > NUL
Expand Down
61 changes: 48 additions & 13 deletions tools/codegenerator/SwigTypeParser.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public class SwigTypeParser
*/
private static Map typeTable = [:]

/**
* Add a typedef node to the global list of typedefs to be used later in
* parsing types.
*/
public static void appendTypeTable(Node typetab) { typetab.each { typeTable[it.@namespace + it.@type] = it.@basetype } }

/**
Expand Down Expand Up @@ -128,25 +132,56 @@ public class SwigTypeParser
return result.replaceAll('<\\(', '<').replaceAll('\\)>', '>')
}

/**
* This will resolve the typedefs given the parameter passed is a simple type.
* see SwigType_resolve_all_typedefs which will handle qualifiers, pointers,
* references, and typedef of typedefs to resolve all the way down to the
* most basic types.
*/
public static String SwigType_typedef_resolve(String t)
{
String td = typeTable[t]
String ret = td == null ? t : td
// System.out.println "trying to resolve ${t} and it appears to be typedefed to ${ret}"
return ret
}

public static String SwigType_typedef_resolve_all(String t)
{
String prev = t
t = SwigType_typedef_resolve(prev)
while(prev != t)
{
String tmp = t
t = SwigType_typedef_resolve(prev)
prev = tmp
/**
* This will resolve typedefs anbd handle qualifiers, pointers,
* references, and typedef of typedefs to resolve all the way down to the
* most basic types.
*/
public static String SwigType_resolve_all_typedefs(String s)
{
String result = ''
String tc = s

/* Nuke all leading qualifiers, appending them to the result*/
while (SwigType_isqualifier(tc)) {
List tmpl = SwigType_pop(tc)
tc = tmpl[1]
result += tmpl[0]
}

if (SwigType_issimple(tc)) {
/* Resolve any typedef definitions */
String tt = tc
String td
while ((td = SwigType_typedef_resolve(tt)) != tt) {
if (td != tt) {
tt = td
break
}
else if (td != tt) tt = td
}
tc = td

return tc
}
return t

List tmpl = SwigType_pop(tc)
result += tmpl[0]
result += SwigType_resolve_all_typedefs(tmpl[1])
return result
}

/**
Expand Down Expand Up @@ -205,7 +240,7 @@ public class SwigTypeParser
firstarray = false
} else if (SwigType_isreference(element)) {
if (notypeconv) {
result == element
result += element
} else {
result += "p."
}
Expand All @@ -216,7 +251,7 @@ public class SwigTypeParser
} else {
result += "p."
}
firstarray = 0;
firstarray = false;
} else if (SwigType_isenum(element)) {
boolean anonymous_enum = (element == "enum ")
if (notypeconv || !anonymous_enum) {
Expand Down
73 changes: 73 additions & 0 deletions xbmc/commons/typeindex.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright (C) 2005-2013 Team XBMC
* http://xbmc.org
*
* 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, 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 XBMC; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/

#include <typeinfo>

/**
* This struct represents a pre-introduction of the std::type_index for RTTI
* which will only availalbe in C++11.
*/

namespace XbmcCommons
{
/**
@brief The class type_index provides a simple wrapper for type_info
which can be used as an index type in associative containers (23.6)
and in unordered associative containers (23.7).
*/
struct type_index
{
inline type_index(const std::type_info& __rhs)
: _M_target(&__rhs) { }

inline bool
operator==(const type_index& __rhs) const
{ return *_M_target == *__rhs._M_target; }

inline bool
operator!=(const type_index& __rhs) const
{ return *_M_target != *__rhs._M_target; }

inline bool
operator<(const type_index& __rhs) const
{ return _M_target->before(*__rhs._M_target); }

inline bool
operator<=(const type_index& __rhs) const
{ return !__rhs._M_target->before(*_M_target); }

inline bool
operator>(const type_index& __rhs) const
{ return __rhs._M_target->before(*_M_target); }

inline bool
operator>=(const type_index& __rhs) const
{ return !_M_target->before(*__rhs._M_target); }

inline const char*
name() const
{ return _M_target->name(); }

private:
const std::type_info* _M_target;
};

template<typename _Tp> struct hash;
}
1 change: 1 addition & 0 deletions xbmc/cores/VideoRenderers/RenderManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "settings/VideoSettings.h"
#include "OverlayRenderer.h"
#include <deque>
#include "PlatformDefs.h"

class CRenderCapture;

Expand Down
2 changes: 1 addition & 1 deletion xbmc/interfaces/legacy/Addon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace XBMCAddon

String Addon::getAddonVersion() { return languageHook == NULL ? emptyString : languageHook->GetAddonVersion(); }

Addon::Addon(const char* cid) throw (AddonException) : AddonClass("Addon")
Addon::Addon(const char* cid) throw (AddonException)
{
String id(cid ? cid : emptyString);

Expand Down
1 change: 0 additions & 1 deletion xbmc/interfaces/legacy/Addon.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ namespace XBMCAddon
* - version = self.Addon.getAddonInfo('version')
*/
String getAddonInfo(const char* id) throw (AddonException);

};
}
}
7 changes: 4 additions & 3 deletions xbmc/interfaces/legacy/AddonCallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,17 @@ namespace XBMCAddon

bool hasHandler() { return handler.isNotNull(); }

public:
inline AddonCallback(const char* classname) : AddonClass(classname), handler(NULL)
inline AddonCallback() : handler(NULL)
{
// if there is a LanguageHook, it should be set already.
if (languageHook != NULL)
setHandler(languageHook->GetCallbackHandler());
}
public:

virtual ~AddonCallback();

void setHandler(CallbackHandler* _handler) { handler = _handler; }
inline void setHandler(CallbackHandler* _handler) { handler = _handler; }
void invokeCallback(Callback* callback);
};
}
23 changes: 6 additions & 17 deletions xbmc/interfaces/legacy/AddonClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,14 @@ namespace XBMCAddon
if (languageHook != NULL)
languageHook->Release();

#ifdef ENABLE_TRACE_API
TraceGuard tg_;
CLog::Log(LOGDEBUG, "%sNEWADDON destroying %s 0x%lx", tg_.getSpaces(), classname.c_str(), (long)(((void*)this)));
#endif

#ifdef XBMC_ADDON_DEBUG_MEMORY
isDeleted = false;
#endif
}

AddonClass::AddonClass(const char* cname) : refs(0L), classname(cname), m_isDeallocating(false),
languageHook(NULL)
AddonClass::AddonClass() : refs(0L), m_isDeallocating(false),
languageHook(NULL)
{
#ifdef ENABLE_TRACE_API
TraceGuard tg_;
CLog::Log(LOGDEBUG, "%sNEWADDON constructing %s 0x%lx", tg_.getSpaces(), classname.c_str(), (long)(((void*)this)));
#endif

#ifdef XBMC_ADDON_DEBUG_MEMORY
isDeleted = false;
#endif
Expand All @@ -78,11 +68,11 @@ namespace XBMCAddon
{
if (isDeleted)
CLog::Log(LOGERROR,"NEWADDON REFCNT Releasing dead class %s 0x%lx",
classname.c_str(), (long)(((void*)this)));
GetClassname(), (long)(((void*)this)));

long ct = AtomicDecrement((long*)&refs);
#ifdef LOG_LIFECYCLE_EVENTS
CLog::Log(LOGDEBUG,"NEWADDON REFCNT decrementing to %ld on %s 0x%lx", ct,classname.c_str(), (long)(((void*)this)));
CLog::Log(LOGDEBUG,"NEWADDON REFCNT decrementing to %ld on %s 0x%lx", GetClassname(), (long)(((void*)this)));
#endif
if(ct == 0)
{
Expand All @@ -96,16 +86,15 @@ namespace XBMCAddon
{
if (isDeleted)
CLog::Log(LOGERROR,"NEWADDON REFCNT Acquiring dead class %s 0x%lx",
classname.c_str(), (long)(((void*)this)));
GetClassname(), (long)(((void*)this)));

#ifdef LOG_LIFECYCLE_EVENTS
CLog::Log(LOGDEBUG,"NEWADDON REFCNT incrementing to %ld on %s 0x%lx",
AtomicIncrement((long*)&refs),classname.c_str(), (long)(((void*)this)));
AtomicIncrement((long*)&refs),GetClassname(), (long)(((void*)this)));
#else
AtomicIncrement((long*)&refs);
#endif
}

#endif
}

Expand Down
41 changes: 15 additions & 26 deletions xbmc/interfaces/legacy/AddonClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,19 @@ namespace XBMCAddon
* If a scripting language bindings require specific handling there is a
* hook to add in these language specifics that can be set here.
*/
class AddonClass
class AddonClass : public CCriticalSection
{
private:
long refs;
String classname;
CCriticalSection thisLock;
bool m_isDeallocating;

// no copying
inline AddonClass(const AddonClass&);


#ifdef XBMC_ADDON_DEBUG_MEMORY
bool isDeleted;
#endif

friend class Synchronize;
protected:
LanguageHook* languageHook;

Expand All @@ -92,15 +89,21 @@ namespace XBMCAddon
*/
virtual void deallocating()
{
Synchronize lock(*this);
CSingleLock lock(*this);
m_isDeallocating = true;
}

/**
* This is meant to be called during static initialization and so isn't
* synchronized.
*/
static short getNextClassIndex();

public:
AddonClass(const char* classname);
AddonClass();
virtual ~AddonClass();

inline const String& GetClassname() const { return classname; }
inline const char* GetClassname() const { return typeid(*this).name(); }
inline LanguageHook* GetLanguageHook() { return languageHook; }

/**
Expand All @@ -110,6 +113,8 @@ namespace XBMCAddon
*/
bool isDeallocating() { TRACE; return m_isDeallocating; }

static short getNumAddonClasses();

#ifdef XBMC_ADDON_DEBUG_MEMORY
virtual
#else
Expand All @@ -120,7 +125,7 @@ namespace XBMCAddon
{
long ct = AtomicDecrement((long*)&refs);
#ifdef LOG_LIFECYCLE_EVENTS
CLog::Log(LOGDEBUG,"NEWADDON REFCNT decrementing to %ld on %s 0x%lx", ct,classname.c_str(), (long)(((void*)this)));
CLog::Log(LOGDEBUG,"NEWADDON REFCNT decrementing to %ld on %s 0x%lx", ct,GetClassname(), (long)(((void*)this)));
#endif
if(ct == 0)
delete this;
Expand All @@ -140,7 +145,7 @@ namespace XBMCAddon
{
#ifdef LOG_LIFECYCLE_EVENTS
CLog::Log(LOGDEBUG,"NEWADDON REFCNT incrementing to %ld on %s 0x%lx",
AtomicIncrement((long*)&refs),classname.c_str(), (long)(((void*)this)));
AtomicIncrement((long*)&refs),GetClassname(), (long)(((void*)this)));
#else
AtomicIncrement((long*)&refs);
#endif
Expand Down Expand Up @@ -207,21 +212,5 @@ namespace XBMCAddon
inline void reset() { refcheck; if (ac) ac->Release(); ac = NULL; }
};

/**
* This class can be used like a "synchronize" block in java as long
* as the object is an AddonClass. It can be used to synchronize on
* 'this' effectively creating the effect of a synchronize keyword
* on a method declaration.
*
* Keep in mind that this DOES NOT use 'monitor' semantics, but
* uses MUTEX semantics. That means that using this class, a thread
* can deadlock itself, while in java a synchronize keyword won't.
*/
class Synchronize : public CSingleLock
{
public:
inline Synchronize(const AddonClass& obj) : CSingleLock(obj.thisLock) {}
};

};
}

0 comments on commit 1ae84d9

Please sign in to comment.