automatic commit
[universe.git] / task.cc
1
2 ////////////////////////////////////////////////////////////////////////////////
3 // This program is free software; you can redistribute it and/or              //
4 // modify it under the terms of the GNU General Public License                //
5 // version 2 as published by the Free Software Foundation.                    //
6 //                                                                            //
7 // This program is distributed in the hope that it will be useful, but        //
8 // WITHOUT ANY WARRANTY; without even the implied warranty of                 //
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU          //
10 // General Public License for more details.                                   //
11 //                                                                            //
12 // Written and (C) by François Fleuret                                        //
13 // Contact <francois.fleuret@epfl.ch> for comments & bug reports              //
14 ////////////////////////////////////////////////////////////////////////////////
15
16 #include <iostream>
17 #include <dlfcn.h>
18
19 using namespace std;
20
21 #include "task.h"
22 #include "universe.h"
23 #include "manipulator.h"
24
25 Task::~Task() { }
26
27 typedef Task *TaskConstructor();
28
29 Task *load_task(char *filename) {
30   void *handle = dlopen(filename, RTLD_NOW | RTLD_GLOBAL);
31
32   if(handle == 0) {
33     cerr << "Error in dynamic loading: " << dlerror() << "." << endl;
34     exit(1);
35   }
36
37   TaskConstructor *creator = (TaskConstructor *) dlsym(handle, "new_task");
38
39   if(creator == 0) {
40     dlclose(handle);
41     cerr << "Error looking for function new_task() in " << filename << "." << endl;
42     exit(1);
43   }
44
45   return (*creator)();
46 }