{"id":354,"date":"2008-07-18T03:29:43","date_gmt":"2008-07-18T07:29:43","guid":{"rendered":"http:\/\/www.rakkar.org\/blog\/?p=354"},"modified":"2008-07-18T03:29:43","modified_gmt":"2008-07-18T07:29:43","slug":"boostbind-and-boostfunction-for-rpc","status":"publish","type":"post","link":"https:\/\/rakkar.org\/blog\/index.php\/2008\/07\/18\/boostbind-and-boostfunction-for-rpc\/","title":{"rendered":"boost::bind and boost::function for RPC"},"content":{"rendered":"<p>\t\t\t\tBased on forum suggestions I&#8217;m looking into boost::bind and boost::function to do RPC calls rather than my current assembly code based system.<\/p>\n<p>I may be misunderstanding what it does, but I believe that boost::function is a way to store function pointers (regular or object member). And boost::bind allows you to bind parameters to function pointers. Using templates, you can pass complex object types on the stack. My existing assembly implementation can only pass simple structures.<\/p>\n<p>If I&#8217;m correct, I can do something like this:<\/p>\n<p>void DoSomething(MyObject myObject) {&#8230;}<br \/>\nCall(&#8220;DoSomething&#8221;, myObject);<br \/>\n(On the remote system)<br \/>\nboost::function ptrToDoSomething;<br \/>\n(use boost::bind to bind a stack based instance of MyObject to DoSomething)<br \/>\n(Somehow call DoSomething)<\/p>\n<p>I&#8217;m a bit vague on the details now but if it works it will compile out to what is essentially a native function call.<\/p>\n<p>Another problem with my existing implementation of RPC is I am using memcpy for the parameter list. This won&#8217;t work with complex types that have custom serialization &#8211; even including strings. But by overloading < < and >> I can add support for this.<\/p>\n<p>Normal types get a general template.<\/p>\n<p>template &lt;class templateType&gt;<br \/>\nBitStream&#038; operator&lt;&lt;(BitStream&#038; out, const templateType&#038; c)<br \/>\n{<br \/>\n\tout.Write(c);<br \/>\n\treturn out;<br \/>\n}<br \/>\ntemplate &lt;class templateType&gt;<br \/>\nBitStream&#038; operator&gt;&gt;(BitStream&#038; in, templateType&#038; c)<br \/>\n{<br \/>\n\tbool success = in.Read(c);<br \/>\n\tassert(success);<br \/>\n\treturn in;<br \/>\n}<\/p>\n<p>The user can then overload types for a particular class, just replace tempateType with the name of the relevant class.<\/p>\n<p>If this all works out I will finally have the ultimate implementation of RPC calls.<\/p>\n<p>1. Works with C functions and object member functions, including those that use multiple inheritance, with an arbitrary inheritance order<br \/>\n2. Can pass types that use complex serialization (such as my string compression).<br \/>\n3. Can call functions that take complex types in the parameter list, types that cannot fit in a single register.<br \/>\n4. I think I can even do automatic object pointer lookups within parameter lists<\/p>\n<p>In other words, the ability to call any authorized function on a remote system, using any type of parameter, including referenced pointers, with any type of data. Pretty exciting \ud83d\ude42\t\t<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Based on forum suggestions I&#8217;m looking into boost::bind and boost::function to do RPC calls rather than my current assembly code based system. I may be misunderstanding what it does, but I believe that boost::function is a way to store function pointers (regular or object member). And boost::bind allows you to bind parameters to function pointers. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[],"_links":{"self":[{"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/posts\/354"}],"collection":[{"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=354"}],"version-history":[{"count":0,"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/posts\/354\/revisions"}],"wp:attachment":[{"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=354"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=354"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=354"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}