-CPPFLAGS=-g3 -Wall -I/usr/include/libxml++-1.0 -I/usr/include/libxml2 -DDEBUG
+DEBUG=-g3 -DDEBUG -Wall
+#CPPFLAGS=-g3 -Wall -I/usr/include/libxml++-1.0 -I/usr/include/libxml2 -DDEBUG
#CPPFLAGS=-O3 -Wall -I/usr/include/libxml++-1.0 -I/usr/include/libxml2
-LDFLAGS=-lxml++-0.1 #-lxml
+TAGETS=hit.o ghit.o chit.o widget.o container.o fallback.o string.o
-TAGETS=hit.o ghit.o chit.o widget.o container.o fallback.o string.o translate.o parser.o
-
-all: main
+all: parser_test
main: $(TAGETS)
-parser_test: $(TAGETS)
+
+CPPFLAGS=-fPIC $(DEBUG)
hit.o: hit.h hit.cpp
+ghit.o: hit.o ghit.h ghit.cpp
+chit.o: ghit.o chit.h chit.cpp
+
+widget.o: widget.h widget.cpp
+string.o: widget.o string.h string.cpp
+container.o: widget.o container.h container.cpp
+fallback.o: container.o fallback.h fallback.cpp
+
+translate.o: translate.h translate.cpp
+translate_loader.o: translate_loader.cpp
+#.o: .o .h .cpp
+
+# LIBBIFE
+LIBBIFE_TARGETS=hit.o ghit.o chit.o widget.o string.o container.o fallback.o
+libbife.so: $(LIBBIFE_TARGETS)
+ $(CXX) $(DEBUG) -Wl,-soname,libbife.so -shared -o libbife.so $(LIBBIFE_TARGETS)
+
+# TRANSLATE FALLBACK PLUG-IN
+TRANSLATE_TARGETS=translate.o translate_loader.o
+translate.so: libbife.so $(TRANSLATE_TARGETS)
+ $(CXX) $(DEBUG) -L. -lbife -Wl,-soname,translate.so -shared -o translate.so $(TRANSLATE_TARGETS)
+
+
+# Parser example.
+PARSER_FLAGS=-I/usr/include/libxml++-1.0 -I/usr/include/libxml2
+parser.o: parser.h parser.cpp
+ $(CXX) $(DEBUG) $(PARSER_FLAGS) -c parser.cpp
+parser_test.o: parser_test.cpp
+ $(CXX) $(DEBUG) $(PARSER_FLAGS) -c parser_test.cpp
+
+PARSER_TARGETS=parser.o parser_test.o
+parser_test: translate.so $(PARSER_TARGETS)
+ $(CXX) $(DEBUG) $(PARSER_FLAGS) -L. -lxml++-0.1 -ldl -lbife -o parser_test $(PARSER_TARGETS)
+ @echo
+ @echo ----------------------------------------------
+ @echo export LD_LIBRARY_PATH=.
+ @echo to use ./parser_test
clean:
@rm -f *.o main parser_test
// vim: set expandtab tabstop=4 shiftwidth=4:
-// FIXME - ver tema de fallback.
-#include "translate.h"
-
+#include "widget.h"
+#include "container.h"
+#include "fallback.h"
#include "string.h"
#include "parser.h"
#include <sstream>
+#include <dlfcn.h>
using std::stringstream;
using namespace bife;
}
cerr << "]);" << endl;
#endif
- stack.push(new Translate(name, attrs));
+ stack.push(fb_create(name, attrs));
}
void Parser::on_end_element(const string& name) {
#endif
}
-Parser::Parser(void): root(NULL) {
+Parser::Parser(void): fb_create(NULL), fb_destroy(NULL), root(NULL) {
#ifdef DEBUG
cerr << "In Parser::Parser();" << endl;
#endif
+ void* fb = dlopen("./translate.so", RTLD_NOW | RTLD_GLOBAL); // TODO - mas rapido: RTLD_LAZY);
+ if (!fb) {
+ throw string("No se puede cargar el plug-in: ") + dlerror();
+ }
+ fb_create = (create_t*)dlsym(fb, "create");
+ fb_destroy = (destroy_t*)dlsym(fb, "destroy");
+ if (!fb_create || !fb_destroy) {
+ throw string("No se puede cargar el creador del plug-in: ") + dlerror();
+ }
}
//Parser::Parser(const Hash& attrs): attrs(attrs) {
--- /dev/null
+#include "translate.h"
+#include "widget.h"
+#include "hash.h"
+
+using bife::Translate;
+using bife::Widget;
+using bife::Hash;
+using std::string;
+
+// the types of the class factories
+typedef bife::Widget* create_t(const string& name, const Hash&);
+typedef void destroy_t(Widget*);
+
+// the class factories
+extern "C" Widget* create(const string& name, const Hash& attrs) {
+ return new Translate(name, attrs);
+}
+extern "C" void destroy(Widget* w) {
+ delete w;
+}