CaptureFactory_win.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 "CaptureFactory_private.h"
00025 
00026 #include <windows.h>
00027 
00028 namespace alvar {
00029 
00030 void CaptureFactoryPrivate::setupPluginPaths()
00031 {
00032     // application path and default plugin path
00033     const DWORD bufferSize = 4096;
00034     char applicationBuffer[bufferSize];
00035     DWORD count = GetModuleFileName(NULL, applicationBuffer, bufferSize);
00036     if (count != 0 && count < bufferSize) {
00037         std::string applicationPath(applicationBuffer, count);
00038         applicationPath = std::string(applicationPath, 0, applicationPath.find_last_of("\\"));
00039         mPluginPaths.push_back(applicationPath);
00040         mPluginPaths.push_back(applicationPath + "\\alvarplugins");
00041     }
00042 
00043     // ALVAR library path
00044     parseEnvironmentVariable(std::string("ALVAR_LIBRARY_PATH"));
00045 
00046     // ALVAR plugin path
00047     parseEnvironmentVariable(std::string("ALVAR_PLUGIN_PATH"));
00048 }
00049 
00050 void CaptureFactoryPrivate::parseEnvironmentVariable(const std::string &variable)
00051 {
00052     // acquire environment variable
00053     char *buffer;
00054     std::string path("");
00055     #if defined(_MSC_VER) && (_MSC_VER < 1400)
00056         buffer = getenv(variable.data());
00057                 if (buffer) {
00058                         path = std::string(buffer);
00059                 }
00060     #else
00061         size_t requiredSize;
00062         getenv_s(&requiredSize, NULL, 0, variable.data());
00063         if (requiredSize > 0) {
00064             buffer = (char *)malloc(requiredSize * sizeof(char));
00065             getenv_s(&requiredSize, buffer, requiredSize, variable.data());
00066             path = std::string(buffer, requiredSize - 1);
00067             free(buffer);
00068         }
00069     #endif
00070 
00071     // tokenize paths
00072     char delimitor = ';';
00073     if (!path.empty()) {
00074         std::string::size_type start = 0;
00075         std::string::size_type end = 0;
00076         while ((end = path.find_first_of(delimitor, start)) != std::string::npos) {
00077             std::string tmp(path, start, end - start);
00078             if (!tmp.empty()) {
00079                 mPluginPaths.push_back(tmp);
00080             }
00081             start = end + 1;
00082         }
00083         if (start != path.size()) {
00084             std::string tmp(path, start, std::string::npos);
00085             if (!tmp.empty()) {
00086                 mPluginPaths.push_back(tmp);
00087             }
00088         }
00089     }
00090 }
00091 
00092 std::string CaptureFactoryPrivate::pluginPrefix()
00093 {
00094     return std::string("");
00095 }
00096 
00097 std::string CaptureFactoryPrivate::pluginExtension()
00098 {
00099     return std::string("dll");
00100 }
00101 
00102 } // namespace alvar


ar_track_alvar
Author(s): Scott Niekum
autogenerated on Thu Jun 6 2019 21:12:54