Plugin_unix.cpp
Go to the documentation of this file.
00001 /*
00002  * This file is part of ALVAR, A Library for Virtual and Augmented Reality.
00003  *
00004  * Copyright 2007-2012 VTT Technical Research Centre of Finland
00005  *
00006  * Contact: VTT Augmented Reality Team <alvar.info@vtt.fi>
00007  *          <http://www.vtt.fi/multimedia/alvar.html>
00008  *
00009  * ALVAR is free software; you can redistribute it and/or modify it under the
00010  * terms of the GNU Lesser General Public License as published by the Free
00011  * Software Foundation; either version 2.1 of the License, or (at your option)
00012  * any later version.
00013  *
00014  * This library is distributed in the hope that it will be useful, but WITHOUT
00015  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00016  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
00017  * for more details.
00018  *
00019  * You should have received a copy of the GNU Lesser General Public License
00020  * along with ALVAR; if not, see
00021  * <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>.
00022  */
00023 
00024 #include "Plugin_private.h"
00025 
00026 #include "AlvarException.h"
00027 
00028 #include <dlfcn.h>
00029 #include <sstream>
00030 #include <errno.h>
00031 
00032 namespace alvar {
00033 
00034 class PluginPrivateData
00035 {
00036 public:
00037     PluginPrivateData()
00038         : mHandle(NULL)
00039     {
00040     }
00041     
00042     void *mHandle;
00043 };
00044 
00045 PluginPrivate::PluginPrivate()
00046     : d(new PluginPrivateData())
00047 {
00048 }
00049 
00050 PluginPrivate::~PluginPrivate()
00051 {
00052     delete d;
00053 }
00054 
00055 void PluginPrivate::load(const std::string filename)
00056 {
00057     d->mHandle = dlopen(filename.data(), RTLD_LAZY);
00058     if (!d->mHandle) {
00059         std::stringstream message;
00060         message << "could not load " << filename
00061                 << ", error code " << errno;
00062         throw AlvarException(message.str().data());
00063     }
00064 }
00065 
00066 void PluginPrivate::unload()
00067 {
00068     dlclose(d->mHandle);
00069 }
00070 
00071 void *PluginPrivate::resolve(const char *symbol)
00072 {
00073     void *address = (void *)dlsym(d->mHandle, symbol);
00074     if (!address) {
00075         std::stringstream message;
00076         message << "could not resolve " << symbol;
00077         throw AlvarException(message.str().data());
00078     }
00079     return address;
00080 }
00081 
00082 } // namespace alvar


ar_track_alvar
Author(s): Scott Niekum
autogenerated on Sun Oct 5 2014 22:16:26