Package.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * 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 this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package ArmarXCore::core
19  * @author Dennis Weigelt
20  * @date 2016
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 
26 #include "Package.h"
27 #include <filesystem>
28 #ifndef _WIN32
29 #include <fcntl.h> /* Definition of AT_* constants */
30 #include <unistd.h>
31 #endif
33 using namespace ScenarioManager;
34 
35 Data_Structure::Package::Package(std::string name, std::string path, std::string scenarioPath)
36  : name(name),
37  path(path),
38  scenarioPath(scenarioPath),
39  scenarios(new std::vector<Data_Structure::ScenarioPtr>()),
40  applications(new std::vector<Data_Structure::ApplicationPtr>())
41 {
42 }
43 
44 Data_Structure::Package::Package(const Data_Structure::Package& other) : name(other.name), path(other.path)
45 {
46 }
47 
49 {
50  return this->name;
51 }
52 
54 {
55  return this->path;
56 }
57 
59 {
60  return this->scenarioPath;
61 }
62 
64 {
66 
67  ARMARX_VERBOSE << scenarioPath;
68 
69  return true;
70 
71  // bool writable = faccessat(0, scenarioPath.c_str(), W_OK, AT_EACCESS) == 0;
72  // if (!writable)
73  // {
74  // std::filesystem::path scenarioDir(scenarioPath.c_str());
75  // if (!std::filesystem::is_directory(scenarioDir))
76  // {
77  // if (std::filesystem::create_directory(scenarioDir))
78  // {
79  // ARMARX_DEBUG << "Created Scenario dir for Package " << name;
80  // writable = true;
81  // }
82  // else
83  // {
84  // ARMARX_DEBUG << "Failed to create Scenario dir for Package " << name << " please check if you have the certain permissions";
85  // }
86  // }
87  // }
88  // ARMARX_DEBUG << scenarioPath << " is writeable: " << writable;
89  // return writable;
90 }
91 
92 
93 
95 {
96  return this->scenarios;
97 }
98 
100 {
101  return this->applications;
102 }
103 
105 {
106  scenarios->push_back(scenario);
107 }
108 
110 {
111  for (auto it = scenarios->begin(); it != scenarios->end(); ++it)
112  {
113  if ((*it)->getName().compare(scenario->getName()) == 0 && (*it)->getPackage()->getName().compare(scenario->getPackage()->getName()) == 0)
114  {
115  scenarios->erase(it);
116  return;
117  }
118  }
119 }
120 
122 {
123  applications->push_back(application);
124 }
125 
127 {
128  for (std::vector<ScenarioPtr>::iterator iter = scenarios->begin(); iter != scenarios->end(); ++iter)
129  {
130  if (iter->get()->getName().compare(name) == 0)
131  {
132  return *iter;
133  }
134  }
135  return ScenarioPtr();
136 }
137 
138 Data_Structure::ApplicationPtr Data_Structure::Package::getApplicationByName(std::string name) //same as getScenarioByName(...)
139 {
140  for (std::vector<ApplicationPtr>::iterator iter = applications->begin(); iter != applications->end(); ++iter)
141  {
142  if (iter->get()->getName().compare(name) == 0)
143  {
144  return *iter;
145  }
146  }
147  return ApplicationPtr();
148 }
ScenarioManager::Data_Structure::Package::Package
Package(std::string name, std::string path, std::string scenarioPath)
Constructor that sets the name and the path of the package.
Definition: Package.cpp:35
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:180
ScenarioManager::Data_Structure::Package::getPath
std::string getPath()
Definition: Package.cpp:53
ScenarioManager::Data_Structure::ScenarioPtr
std::shared_ptr< Scenario > ScenarioPtr
Definition: Scenario.h:36
ScenarioManager::Data_Structure::ApplicationVectorPtr
std::shared_ptr< std::vector< ApplicationPtr > > ApplicationVectorPtr
Definition: Application.h:120
ScenarioManager::Data_Structure::ApplicationPtr
std::shared_ptr< Application > ApplicationPtr
Definition: Application.h:119
ScenarioManager::Data_Structure::Package::getName
std::string getName()
Definition: Package.cpp:48
ScenarioManager::Data_Structure::Package::addApplication
void addApplication(ApplicationPtr application)
Adds an Application to this package.
Definition: Package.cpp:121
ScenarioManager::Data_Structure::Package::getApplications
ApplicationVectorPtr getApplications()
Definition: Package.cpp:99
ScenarioManager::Data_Structure::Package::getApplicationByName
ApplicationPtr getApplicationByName(std::string name)
Returns an Application contained in this package that has the given name.
Definition: Package.cpp:138
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:69
Package.h
ScenarioManager::Data_Structure::Package::addScenario
void addScenario(ScenarioPtr scenario)
Adds a Scenario to this package.
Definition: Package.cpp:104
ScenarioManager::Data_Structure::Package::removeScenario
void removeScenario(ScenarioPtr scenario)
Definition: Package.cpp:109
ScenarioManager::Data_Structure::Package::isScenarioPathWritable
bool isScenarioPathWritable()
Definition: Package.cpp:63
ScenarioManager
Definition: Application.cpp:166
std
Definition: Application.h:66
ScenarioManager::Data_Structure::Package::getScenarioByName
ScenarioPtr getScenarioByName(std::string name)
Returns a Scenario contained in this package that has the given name.
Definition: Package.cpp:126
ScenarioManager::Data_Structure::Package::getScenarioPath
std::string getScenarioPath()
Definition: Package.cpp:58
Logging.h
ScenarioManager::Data_Structure::Package
Class containing data about a package, its scenarios and its applications. Provides methods to get an...
Definition: Package.h:45
ScenarioManager::Data_Structure::Package::getScenarios
ScenarioVectorPtr getScenarios()
Definition: Package.cpp:94
ScenarioManager::Data_Structure::ScenarioVectorPtr
std::shared_ptr< std::vector< ScenarioPtr > > ScenarioVectorPtr
Definition: Scenario.h:38