71002c3c187aff3c4058d8a1516195c1fd72cf30
[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 // $Id: task.cc,v 1.8 2006-07-10 15:19:06 fleuret Exp $
17
18 #include <iostream>
19 #include <dlfcn.h>
20
21 using namespace std;
22
23 #include "task.h"
24 #include "universe.h"
25 #include "manipulator.h"
26
27 Task::~Task() { }
28
29 typedef Task *TaskConstructor();
30
31 Task *load_task(char *filename) {
32   void *handle = dlopen(filename, RTLD_NOW | RTLD_GLOBAL);
33
34   if(handle == 0) {
35     cerr << "Error in dynamic loading: " << dlerror() << "." << endl;
36     exit(1);
37   }
38
39   TaskConstructor *creator = (TaskConstructor *) dlsym(handle, "new_task");
40
41   if(creator == 0) {
42     dlclose(handle);
43     cerr << "Error looking for function new_task() in " << filename << "." << endl;
44     exit(1);
45   }
46
47   return (*creator)();
48 }