Clean-ups to logging and type signatures
[invirt/third/libt4.git] / rsm_client.h
index 0b1dc88..2a9c8c4 100644 (file)
@@ -29,30 +29,41 @@ class rsm_client {
         template<class R> int call_m(unsigned int proc, R & r, const marshall & req);
 };
 
         template<class R> int call_m(unsigned int proc, R & r, const marshall & req);
 };
 
+inline string hexify(const string & s) {
+    string bytes;
+    for (char ch : s) {
+        bytes.push_back("0123456789abcdef"[(uint8_t)ch >> 4]);
+        bytes.push_back("0123456789abcdef"[(uint8_t)ch & 15]);
+    }
+    return bytes;
+}
+
 template<class R>
 int rsm_client::call_m(unsigned int proc, R & r, const marshall & req) {
     string rep;
     string res;
 template<class R>
 int rsm_client::call_m(unsigned int proc, R & r, const marshall & req) {
     string rep;
     string res;
-    int intret = invoke(proc, rep, req);
+    int intret = invoke(proc, rep, req.content());
     VERIFY( intret == rsm_client_protocol::OK );
     unmarshall u(rep, false);
     u >> intret;
     if (intret < 0) return intret;
     u >> res;
     if (!u.okdone()) {
     VERIFY( intret == rsm_client_protocol::OK );
     unmarshall u(rep, false);
     u >> intret;
     if (intret < 0) return intret;
     u >> res;
     if (!u.okdone()) {
-        cerr << "rsm_client::call_m: failed to unmarshall the reply." << endl;
-        cerr << "You probably forgot to set the reply string in "
-                "rsm::client_invoke, or you may have called RPC 0x" << hex <<
-                proc << " with the wrong return type" << endl;
+        LOG("failed to unmarshall the reply.");
+        LOG("You probably forgot to set the reply string in " <<
+            "rsm::client_invoke, or you may have called RPC " <<
+            "0x" << hex << proc << " with the wrong return type");
+        LOG("here's what I got: \"" << hexify(rep) << "\"");
         VERIFY(0);
         return rpc_const::unmarshal_reply_failure;
     }
     unmarshall u1(res, false);
     u1 >> r;
     if(!u1.okdone()) {
         VERIFY(0);
         return rpc_const::unmarshal_reply_failure;
     }
     unmarshall u1(res, false);
     u1 >> r;
     if(!u1.okdone()) {
-        cerr << "rsm_client::call_m: failed to unmarshall the reply." << endl;
-        cerr << "You are probably calling RPC 0x" << hex << proc <<
-                " with the wrong return type." << endl;
+        LOG("failed to unmarshall the reply.");
+        LOG("You are probably calling RPC 0x" << hex << proc <<
+            " with the wrong return type.");
+        LOG("here's what I got: \"" << hexify(res) << "\"");
         VERIFY(0);
         return rpc_const::unmarshal_reply_failure;
     }
         VERIFY(0);
         return rpc_const::unmarshal_reply_failure;
     }