summaryrefslogtreecommitdiffstats
path: root/xbmc/addons/include/xbmc_addon_cpp_dll.h
diff options
context:
space:
mode:
Diffstat (limited to 'xbmc/addons/include/xbmc_addon_cpp_dll.h')
-rw-r--r--xbmc/addons/include/xbmc_addon_cpp_dll.h191
1 files changed, 191 insertions, 0 deletions
diff --git a/xbmc/addons/include/xbmc_addon_cpp_dll.h b/xbmc/addons/include/xbmc_addon_cpp_dll.h
new file mode 100644
index 0000000..3944525
--- /dev/null
+++ b/xbmc/addons/include/xbmc_addon_cpp_dll.h
@@ -0,0 +1,191 @@
1#ifndef __XBMC_ADDON_CPP_H__
2#define __XBMC_ADDON_CPP_H__
3
4/*
5 * Copyright (C) 2005-2013 Team XBMC
6 * http://xbmc.org
7 *
8 * This Program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
11 * any later version.
12 *
13 * This Program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with XBMC; see the file COPYING. If not, see
20 * <http://www.gnu.org/licenses/>.
21 *
22 */
23
24#include "xbmc_addon_types.h"
25
26#include <vector>
27#include <string.h>
28#include <stdlib.h>
29
30class DllSetting
31{
32public:
33 enum SETTING_TYPE { NONE=0, CHECK, SPIN };
34
35 DllSetting(SETTING_TYPE t, const char *n, const char *l)
36 {
37 id = NULL;
38 label = NULL;
39 if (n)
40 {
41 id = new char[strlen(n)+1];
42 strcpy(id, n);
43 }
44 if (l)
45 {
46 label = new char[strlen(l)+1];
47 strcpy(label, l);
48 }
49 current = 0;
50 type = t;
51 }
52
53 DllSetting(const DllSetting &rhs) // copy constructor
54 {
55 id = NULL;
56 label = NULL;
57 if (rhs.id)
58 {
59 id = new char[strlen(rhs.id)+1];
60 strcpy(id, rhs.id);
61 }
62 if (rhs.label)
63 {
64 label = new char[strlen(rhs.label)+1];
65 strcpy(label, rhs.label);
66 }
67 current = rhs.current;
68 type = rhs.type;
69 for (unsigned int i = 0; i < rhs.entry.size(); i++)
70 {
71 char *lab = new char[strlen(rhs.entry[i]) + 1];
72 strcpy(lab, rhs.entry[i]);
73 entry.push_back(lab);
74 }
75 }
76
77 ~DllSetting()
78 {
79 delete[] id;
80 delete[] label;
81 for (unsigned int i=0; i < entry.size(); i++)
82 delete[] entry[i];
83 }
84
85 void AddEntry(const char *label)
86 {
87 if (!label || type != SPIN) return;
88 char *lab = new char[strlen(label) + 1];
89 strcpy(lab, label);
90 entry.push_back(lab);
91 }
92
93 // data members
94 SETTING_TYPE type;
95 char* id;
96 char* label;
97 int current;
98 std::vector<const char *> entry;
99};
100
101class DllUtils
102{
103public:
104
105 static unsigned int VecToStruct(std::vector<DllSetting> &vecSet, ADDON_StructSetting*** sSet)
106 {
107 *sSet = NULL;
108 if(vecSet.size() == 0)
109 return 0;
110
111 unsigned int uiElements=0;
112
113 *sSet = (ADDON_StructSetting**)malloc(vecSet.size()*sizeof(ADDON_StructSetting*));
114 for(unsigned int i=0;i<vecSet.size();i++)
115 {
116 (*sSet)[i] = NULL;
117 (*sSet)[i] = (ADDON_StructSetting*)malloc(sizeof(ADDON_StructSetting));
118 (*sSet)[i]->id = NULL;
119 (*sSet)[i]->label = NULL;
120 uiElements++;
121
122 if (vecSet[i].id && vecSet[i].label)
123 {
124 (*sSet)[i]->id = strdup(vecSet[i].id);
125 (*sSet)[i]->label = strdup(vecSet[i].label);
126 (*sSet)[i]->type = vecSet[i].type;
127 (*sSet)[i]->current = vecSet[i].current;
128 (*sSet)[i]->entry_elements = 0;
129 (*sSet)[i]->entry = NULL;
130 if(vecSet[i].type == DllSetting::SPIN && vecSet[i].entry.size() > 0)
131 {
132 (*sSet)[i]->entry = (char**)malloc(vecSet[i].entry.size()*sizeof(char**));
133 for(unsigned int j=0;j<vecSet[i].entry.size();j++)
134 {
135 if(strlen(vecSet[i].entry[j]) > 0)
136 {
137 (*sSet)[i]->entry[j] = strdup(vecSet[i].entry[j]);
138 (*sSet)[i]->entry_elements++;
139 }
140 }
141 }
142 }
143 }
144 return uiElements;
145 }
146
147 static void StructToVec(unsigned int iElements, ADDON_StructSetting*** sSet, std::vector<DllSetting> *vecSet)
148 {
149 if(iElements == 0)
150 return;
151
152 vecSet->clear();
153 for(unsigned int i=0;i<iElements;i++)
154 {
155 DllSetting vSet((DllSetting::SETTING_TYPE)(*sSet)[i]->type, (*sSet)[i]->id, (*sSet)[i]->label);
156 if((*sSet)[i]->type == DllSetting::SPIN)
157 {
158 for(unsigned int j=0;j<(*sSet)[i]->entry_elements;j++)
159 {
160 vSet.AddEntry((*sSet)[i]->entry[j]);
161 }
162 }
163 vSet.current = (*sSet)[i]->current;
164 vecSet->push_back(vSet);
165 }
166 }
167
168 static void FreeStruct(unsigned int iElements, ADDON_StructSetting*** sSet)
169 {
170 if(iElements == 0)
171 return;
172
173 for(unsigned int i=0;i<iElements;i++)
174 {
175 if((*sSet)[i]->type == DllSetting::SPIN)
176 {
177 for(unsigned int j=0;j<(*sSet)[i]->entry_elements;j++)
178 {
179 free((*sSet)[i]->entry[j]);
180 }
181 free((*sSet)[i]->entry);
182 }
183 free((*sSet)[i]->id);
184 free((*sSet)[i]->label);
185 free((*sSet)[i]);
186 }
187 free(*sSet);
188 }
189};
190
191#endif