Merge pull request #4630 from Red-F/gotham-resume-pvr-lastplayedposition
[vuplus_xbmc] / xbmc / DynamicDll.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://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, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 #include "DynamicDll.h"
22 #include "SectionLoader.h"
23 #include "filesystem/File.h"
24 #include "utils/log.h"
25
26 using namespace XFILE;
27
28 DllDynamic::DllDynamic()
29 {
30   m_dll=NULL;
31   m_DelayUnload=true;
32 }
33
34 DllDynamic::DllDynamic(const CStdString& strDllName)
35 {
36   m_strDllName=strDllName;
37   m_dll=NULL;
38   m_DelayUnload=true;
39 }
40
41 DllDynamic::~DllDynamic()
42 {
43   Unload();
44 }
45
46 bool DllDynamic::Load()
47 {
48   if (m_dll)
49     return true;
50
51   if (!(m_dll=CSectionLoader::LoadDLL(m_strDllName, m_DelayUnload, LoadSymbols())))
52     return false;
53
54   if (!ResolveExports())
55   {
56     CLog::Log(LOGERROR, "Unable to resolve exports from dll %s", m_strDllName.c_str());
57     Unload();
58     return false;
59   }
60
61   return true;
62 }
63
64 void DllDynamic::Unload()
65 {
66   if(m_dll)
67     CSectionLoader::UnloadDLL(m_strDllName);
68   m_dll=NULL;
69 }
70
71 bool DllDynamic::CanLoad()
72 {
73   return CFile::Exists(m_strDllName);
74 }
75
76 bool DllDynamic::EnableDelayedUnload(bool bOnOff)
77 {
78   if (m_dll)
79     return false;
80
81   m_DelayUnload=bOnOff;
82
83   return true;
84 }
85
86 bool DllDynamic::SetFile(const CStdString& strDllName)
87 {
88   if (m_dll)
89     return false;
90
91   m_strDllName=strDllName;
92   return true;
93 }
94