CaptureFactory_unix.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ALVAR, A Library for Virtual and Augmented Reality.
3  *
4  * Copyright 2007-2012 VTT Technical Research Centre of Finland
5  *
6  * Contact: VTT Augmented Reality Team <alvar.info@vtt.fi>
7  * <http://www.vtt.fi/multimedia/alvar.html>
8  *
9  * ALVAR is free software; you can redistribute it and/or modify it under the
10  * terms of the GNU Lesser General Public License as published by the Free
11  * Software Foundation; either version 2.1 of the License, or (at your option)
12  * any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
17  * for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with ALVAR; if not, see
21  * <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>.
22  */
23 
25 
26 #include <stdlib.h>
27 #include <unistd.h> // for readlink()
28 
29 namespace alvar {
30 
32 {
33  // application path and default plugin path
34  const int bufferSize = 4096;
35  char applicationBuffer[bufferSize];
36  int count = readlink("/proc/self/exe", applicationBuffer, bufferSize);
37  if (count != 0 && count < bufferSize) {
38  std::string applicationPath(applicationBuffer, count);
39  applicationPath = std::string(applicationPath, 0, applicationPath.find_last_of("/"));
40  mPluginPaths.push_back(applicationPath);
41  mPluginPaths.push_back(applicationPath + "/alvarplugins");
42  }
43 
44  // ALVAR library path
45  parseEnvironmentVariable(std::string("ALVAR_LIBRARY_PATH"));
46 
47  // ALVAR plugin path
48  parseEnvironmentVariable(std::string("ALVAR_PLUGIN_PATH"));
49 }
50 
51 void CaptureFactoryPrivate::parseEnvironmentVariable(const std::string &variable)
52 {
53  // acquire environment variable
54  char *buffer;
55  std::string path("");
56  buffer = getenv(variable.data());
57  if (buffer) {
58  path = std::string(buffer);
59  }
60 
61  // tokenize paths
62  char delimitor = ':';
63  if (!path.empty()) {
64  std::string::size_type start = 0;
65  std::string::size_type end = 0;
66  while ((end = path.find_first_of(delimitor, start)) != std::string::npos) {
67  std::string tmp(path, start, end - start);
68  if (!tmp.empty()) {
69  mPluginPaths.push_back(tmp);
70  }
71  start = end + 1;
72  }
73  if (start != path.size()) {
74  std::string tmp(path, start, std::string::npos);
75  if (!tmp.empty()) {
76  mPluginPaths.push_back(tmp);
77  }
78  }
79  }
80 }
81 
83 {
84  return std::string("lib");
85 }
86 
88 {
89  return std::string("so");
90 }
91 
92 } // namespace alvar
Main ALVAR namespace.
Definition: Alvar.h:174
void parseEnvironmentVariable(const std::string &variable)


ar_track_alvar
Author(s): Scott Niekum
autogenerated on Mon Jun 10 2019 12:47:03