[cosmetics] update date in GPL header
[vuplus_xbmc] / xbmc / interfaces / legacy / AddonUtils.cpp
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
23 #include "AddonUtils.h"
24 #include "guilib/GraphicContext.h"
25 #include "utils/XBMCTinyXML.h"
26 #include "addons/Skin.h"
27 #include "utils/log.h"
28 #include "threads/ThreadLocal.h"
29
30 namespace XBMCAddonUtils
31 {
32   //***********************************************************
33   // Some simple helpers
34   void guiLock()
35   {
36     g_graphicsContext.Lock();
37   }
38
39   void guiUnlock()
40   {
41     g_graphicsContext.Unlock();
42   }
43   //***********************************************************
44   
45   static char defaultImage[1024];
46
47   const char *getDefaultImage(char* cControlType, char* cTextureType, char* cDefault)
48   {
49     // create an xml block so that we can resolve our defaults
50     // <control type="type">
51     //   <description />
52     // </control>
53     TiXmlElement control("control");
54     control.SetAttribute("type", cControlType);
55     TiXmlElement filler("description");
56     control.InsertEndChild(filler);
57     g_SkinInfo->ResolveIncludes(&control);
58
59     // ok, now check for our texture type
60     TiXmlElement *pTexture = control.FirstChildElement(cTextureType);
61     if (pTexture)
62     {
63       // found our textureType
64       TiXmlNode *pNode = pTexture->FirstChild();
65       if (pNode && pNode->Value()[0] != '-')
66       {
67         strncpy(defaultImage, pNode->Value(), sizeof(defaultImage));
68         defaultImage[sizeof(defaultImage) - 1] = '\0';
69         return defaultImage;
70       }
71     }
72     return cDefault;
73   }
74
75 #ifdef ENABLE_TRACE_API
76   static XbmcThreads::ThreadLocal<TraceGuard> tlParent;
77
78   static char** getSpacesArray(int size)
79   {
80     char** ret = new char*[size];
81     for (int i = 0; i < size; i++)
82     {
83       ret[i] = new char[i + 1];
84
85       int j;
86       for (j = 0; j < i; j++)
87         ret[i][j] = ' ';
88       ret[i][j] = 0;
89     }
90     return ret;
91   }
92
93   static char** spaces = getSpacesArray(256);
94
95   const char* TraceGuard::getSpaces() { return spaces[depth]; }
96
97   TraceGuard::TraceGuard(const char* _function) :function(_function) 
98   {
99     parent = tlParent.get();
100     depth = parent == NULL ? 0 : parent->depth + 1;
101
102     tlParent.set(this);
103
104     CLog::Log(LOGDEBUG, "%sNEWADDON Entering %s", spaces[depth], function); 
105   }
106
107   TraceGuard::TraceGuard() :function(NULL) 
108   {
109     parent = tlParent.get();
110     depth = parent == NULL ? 0 : parent->depth + 1;
111     tlParent.set(this);
112     // silent
113   }
114
115   TraceGuard::~TraceGuard() 
116   {
117     if (function)
118       CLog::Log(LOGDEBUG, "%sNEWADDON Leaving %s", spaces[depth], function);
119
120     // need to pop the stack
121     tlParent.set(this->parent);
122   }
123 #endif
124
125
126 }