openrave.org

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
plugin.h
Go to the documentation of this file.
1 // -*- coding: utf-8 -*-
2 // Copyright (C) 2006-2010 Rosen Diankov (rosen.diankov@gmail.com)
3 //
4 // This file is part of OpenRAVE.
5 // OpenRAVE is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // at your option) 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 Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #ifndef OPENRAVE_PLUGIN_H
23 #define OPENRAVE_PLUGIN_H
24 
25 #include <openrave/openrave.h>
26 #include <boost/format.hpp>
27 
28 // export symbol prefix for plugin functions
29 #define OPENRAVE_PLUGIN_API extern "C" OPENRAVE_HELPER_DLL_EXPORT
30 
32 #define RAVE_PLUGIN_API OPENRAVE_PLUGIN_API
33 
45 OpenRAVE::InterfaceBasePtr CreateInterfaceValidated(OpenRAVE::InterfaceType type, const std::string& name, std::istream& sinput, OpenRAVE::EnvironmentBasePtr penv);
46 
56 
59 OPENRAVE_PLUGIN_API OpenRAVE::InterfaceBasePtr OpenRAVECreateInterface(OpenRAVE::InterfaceType type, const std::string& name, const char* interfacehash, const char* envhash, OpenRAVE::EnvironmentBasePtr penv)
60 {
61  if( strcmp(interfacehash,OpenRAVE::RaveGetInterfaceHash(type)) ) {
62  throw OPENRAVE_EXCEPTION_FORMAT("bad interface %s hash: %s!=%s",RaveGetInterfaceName(type)%interfacehash%OpenRAVE::RaveGetInterfaceHash(type),OpenRAVE::ORE_InvalidInterfaceHash);
63  }
64  if( !penv ) {
65  throw OPENRAVE_EXCEPTION_FORMAT0("need to set environment",OpenRAVE::ORE_InvalidArguments);
66  }
67  if( strcmp(envhash,OPENRAVE_ENVIRONMENT_HASH) ) {
68  throw OPENRAVE_EXCEPTION_FORMAT("bad environment hash: %s!=%s",envhash%OPENRAVE_ENVIRONMENT_HASH,OpenRAVE::ORE_InvalidPlugin);
69  }
70  OpenRAVE::RaveInitializeFromState(penv->GlobalState()); // make sure global state is set
71  std::stringstream sinput(name);
72  std::string interfacename;
73  sinput >> interfacename;
74  std::transform(interfacename.begin(), interfacename.end(), interfacename.begin(), ::tolower);
75  return CreateInterfaceValidated(type,interfacename,sinput,penv);
76 }
77 
80 OPENRAVE_PLUGIN_API void OpenRAVEGetPluginAttributes(OpenRAVE::PLUGININFO* pinfo, int size, const char* infohash)
81 {
82  if( pinfo == NULL ) {
84  }
85  if( size != sizeof(OpenRAVE::PLUGININFO) ) {
86  throw OPENRAVE_EXCEPTION_FORMAT("bad plugin info sizes %d != %d", size%sizeof(OpenRAVE::PLUGININFO),OpenRAVE::ORE_InvalidPlugin);
87  }
88  if( strcmp(infohash,OPENRAVE_PLUGININFO_HASH) ) {
89  throw OPENRAVE_EXCEPTION_FORMAT0("bad plugin info hash",OpenRAVE::ORE_InvalidPlugin);
90  }
92  pinfo->version = OPENRAVE_VERSION;
93 }
94 
98 
100 
101 #endif