
Hi,
I've got another issue with PION_STATIC_LINKING on linux (gcc (GCC) 4.1.1 20070105 (Red Hat 4.1.1-52)).
I've write custom WebService and want to make it statically linked into binary.
I've implemented simple MjpegService and add PION_DECLARE_PLUGIN(MjpegService) into main(). Also I've enabled PION_STATIC_LINKING in PionConfig.hpp
On WinXP/msvc 8 all compiles just fine, but on Linux box I've received following issue:
/home/snikulov/SVN/my_wbranch/src/stream_hub/src/stream_hub.cpp: At global scope:
/home/snikulov/SVN/my_wbranch/src/stream_hub/src/stream_hub.cpp:48: error: invalid conversion from ‘MjpegService* (*)()’ to ‘void*’
/home/snikulov/SVN/my_wbranch/src/stream_hub/src/stream_hub.cpp:48: error: initializing argument 2 of ‘pion::StaticEntryPointHelper::StaticEntryPointHelper(const std::string&, void*, void*)’
/home/snikulov/SVN/my_wbranch/src/stream_hub/src/stream_hub.cpp:48: error: invalid conversion from ‘void (*)(MjpegService*)’ to ‘void*’
/home/snikulov/SVN/my_wbranch/src/stream_hub/src/stream_hub.cpp:48: error: initializing argument 3 of ‘pion::StaticEntryPointHelper::StaticEntryPointHelper(const std::string&, void*, void*)’
/home/snikulov/SVN/my_wbranch/src/stream_hub/src/stream_hub.cpp: In function ‘int main(int, char**)’:
I've fixed it with explicit cast to void* in PION_DECLARE_PLUGIN
diff for details (from my internal svn):
svn diff ../include/pion/PionPlugin.hpp -r970:971
Index: ../include/pion/PionPlugin.hpp
===================================================================
--- ../include/pion/PionPlugin.hpp (revision 970)
+++ ../include/pion/PionPlugin.hpp (revision 971)
@@ -417,7 +417,7 @@
class plugin_name; \
extern "C" plugin_name *pion_create_##plugin_name(void); \
extern "C" void pion_destroy_##plugin_name(plugin_name *plugin_ptr); \
- static pion::StaticEntryPointHelper helper_##plugin_name(#plugin_name, pion_create_##plugin_name, pion_destroy_##plugin_name);
+ static pion::StaticEntryPointHelper helper_##plugin_name(#plugin_name, (void*)pion_create_##plugin_name, (void*)pion_destroy_##plugin_name);
/// used by PION_DECLARE_PLUGIN to add an entry point for static-linked plugins
class StaticEntryPointHelper {

With the 0.5.4 release, the code for handling dynamic plugin modules was split out from "HTTPServer" into a "WebServer" class. HTTPServer now lets you bind function objects to resources, allowing you to use static linking without the old PION_STATIC_LINKING macros. For example:
void staticFuncToHandleRequests(HTTPRequestPtr& req_ptr, TCPConnectionPtr& conn_ptr)
{ ... }
...
HTTPServer my_server;
my_server.addResource("/", boost::bind(&staticFuncToHandleRequests, _1, _2));
...
I think this is a much cleaner and easier approach that provides the same functionality and replaces the need for PION_STATIC_LINKING. I'm open to hear arguments to the contrary, but for now I see no reason why we shouldn't remote it.
(Note: a Drupal upgrade gone bad ate my last post, so I had to re-write this response)
- Login or register to post comments
Submitted by Mike Dickey on Tue, 07/22/2008 - 14:19.I'm actually thinking about removing all the STATIC_PLUGIN code.
I don't believe that this feature is relevant now that HTTPServer and WebServer are split out as two separate classes (with the former allowing resources to be bound to any function/object, and the latter adding code for dynamic modules or plugins). I think that the same functionality can be achieved (and in a much cleaner/more standard way) by using HTTPServer instead of WebServer, and linking the cpp files into your application.
Please correct me if I'm missing something here, but unless there are major objections I plan to remove this code from the next release.
- Login or register to post comments
Submitted by Mike Dickey on Mon, 07/21/2008 - 15:56.But currently it present and does not work as I'm expected from the PionWebServer.cpp example ;-) And only on Linux, where gcc does not doing automatic casting to void*
Dynamic modules (I think so) not quite good for embedded devices. So options for make modules dynamic/static during compilation is valuable options for it.
- Login or register to post comments
Submitted by snikulov on Mon, 07/21/2008 - 19:09.