add _httpapi.get
[pykit.git] / PythonPublisher.cc
index fc29b6f..f944b6d 100644 (file)
@@ -13,6 +13,7 @@
 #include <iostream>
 #include <boost/python.hpp>
 #include "Publisher.hh"
+#include <QDesktopServices>
 
 //#include "PythonPublisher.mpp"
 #define prefix_
@@ -26,6 +27,8 @@ struct pykit::PythonPublisher::Impl
     Publisher * pythonPublisher;
 };
 
+#define PYTHON_EXTERN_MODULE(module) \
+    extern "C" { void init ## module (); }
 #define PYTHON_PREPARE_IMPORT(module) \
     PyImport_AppendInittab(const_cast<char*>(#module), init ## module)
 
@@ -434,14 +437,19 @@ BOOST_PYTHON_MODULE(_pykit)
     py::class_<PublisherPyWrapper, boost::noncopyable>("Publisher")
         .def("publish", py::pure_virtual(&pykit::Publisher::publish))
         ;
+
+    py::def("openUrl", &QDesktopServices::openUrl);
 }
 
+PYTHON_EXTERN_MODULE(_httpapi);
+
 prefix_ pykit::PythonPublisher::PythonPublisher()
     : impl_ (new Impl)
 {
     try {
         PYTHON_PREPARE_IMPORT(_pykit);
         PYTHON_PREPARE_IMPORT(_qt);
+        PYTHON_PREPARE_IMPORT(_httpapi);
         Py_Initialize();
         py::object initModule = py::import("init");
         impl_->mainNamespace = py::extract<py::dict>(initModule.attr("__dict__"));
@@ -454,7 +462,12 @@ prefix_ pykit::PythonPublisher::PythonPublisher()
 }
 
 prefix_ pykit::PythonPublisher::~PythonPublisher()
-{}
+{
+    try {
+        impl_->mainNamespace["shutdown"]();
+    }
+    catch (...) {;}
+}
 
 prefix_ void pykit::PythonPublisher::publish(Request & request)
 {