WvStreams
|
00001 /* -*- Mode: C++ -*- 00002 * Worldvisions Weaver Software: 00003 * Copyright (C) 2004-2006 Net Integration Technologies, Inc. 00004 * 00005 * Wrapper code for marshalling/demarshalling WvDBusMsg objects. This is 00006 * in a separate file from WvDBusMsg in case you want to use a WvDBusMsg 00007 * but not our special/gross marshalling code from wvdbusmarshal_c.c. 00008 * 00009 */ 00010 #include "wvdbusmsg.h" 00011 #undef interface // windows 00012 #include <dbus/dbus.h> 00013 00014 WvDBusMsg *WvDBusMsg::demarshal(WvBuf &buf) 00015 { 00016 size_t used = 0; 00017 DBusMessage *_msg = wvdbus_demarshal(buf.peek(0, buf.used()), buf.used(), 00018 &used); 00019 buf.get(used); 00020 if (_msg) 00021 { 00022 WvDBusMsg *msg = new WvDBusMsg(_msg); 00023 dbus_message_unref(_msg); 00024 return msg; 00025 } 00026 else 00027 return NULL; 00028 } 00029 00030 00031 size_t WvDBusMsg::demarshal_bytes_needed(WvBuf &buf) 00032 { 00033 size_t used = buf.used(); 00034 return wvdbus_message_length(buf.peek(0, used), used); 00035 } 00036 00037 00038 void WvDBusMsg::marshal(WvBuf &buf) 00039 { 00040 size_t len; 00041 char *cbuf; 00042 00043 if (wvdbus_marshal(*this, &cbuf, &len)) 00044 { 00045 buf.put(cbuf, len); 00046 free(cbuf); 00047 } 00048 }