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