-
Notifications
You must be signed in to change notification settings - Fork 0
/
arnDeviceLoader.cpp
104 lines (92 loc) · 2.96 KB
/
arnDeviceLoader.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/***************************************************************************
arnDeviceLoader.cpp - description
-------------------
begin : gio giu 3 2004
copyright : (C) 2004 by fgiovagnini
email : fgiovagnini@obione
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#include <dlfcn.h>
#include "arnDeviceLoader.h"
arnDeviceLoader::arnDeviceLoader(const char* devName)
{
__handle = dlopen(devName, RTLD_LAZY);
error = 0;
if (0 == __handle) {
error = dlerror();
}
}
arnDeviceLoader::~arnDeviceLoader()
{
int res = 0;
if(__handle) res = dlclose(__handle);
if (res) arnCriticalExit();
}
arnSOKPDevice* arnDeviceLoader::loadKPDevice(QWidget *parent, const char* name)
{
error = 0;
KPconstructor = (arnSOKPDevice *(*)(QWidget *parent, const char* name))dlsym(__handle, "CreateKPDevice");
if (0 == KPconstructor) {
error = dlerror();
return 0;
}
return ((*KPconstructor)(parent,name));
}
arnSOKCDevice* arnDeviceLoader::loadKCDevice(QWidget *parent, const char* name)
{
error = 0;
KCconstructor = (arnSOKCDevice *(*)(QWidget *parent, const char* name))dlsym(__handle, "CreateKCDevice");
if (0 == KCconstructor) {
error = dlerror();
return 0;
}
return ((*KCconstructor)(parent,name));
}
arnSOKLDevice* arnDeviceLoader::loadKLDevice(QWidget *parent, const char* name)
{
error = 0;
KLconstructor = (arnSOKLDevice *(*)(QWidget *parent, const char* name))dlsym(__handle, "CreateKLDevice");
if (0 == KLconstructor) {
error = dlerror();
return 0;
}
return ((*KLconstructor)(parent,name));
}
arnSOCfg* arnDeviceLoader::loadCfg(QWidget *parent, const char* name)
{
error = 0;
Cfgconstructor = (arnSOCfg *(*)(QWidget *parent, const char* name))dlsym(__handle, "CreateCfg");
if (0 == Cfgconstructor) {
error = dlerror();
return 0;
}
return ((*Cfgconstructor)(parent,name));
}
void arnDeviceLoader::unloadKPDevice(arnSOKPDevice* dev)
{
if (dev) {delete dev; dev = 0;}
}
void arnDeviceLoader::unloadKCDevice(arnSOKCDevice* dev)
{
if (dev) {delete dev;dev = 0;}
}
void arnDeviceLoader::unloadKLDevice(arnSOKLDevice* dev)
{
if (dev) {delete dev; dev = 0;}
}
void arnDeviceLoader::unloadCfg(arnSOCfg* dev)
{
if (dev) {delete dev; dev = 0;}
}
const char* arnDeviceLoader::getError(void)
{
if (error) return error;
return 0;
}