2 * Copyright (c) 2008 Zmanda, Inc. All Rights Reserved.
4 * This library is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 2.1 as
6 * published by the Free Software Foundation.
8 * This library is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
11 * License for more details.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this library; if not, write to the Free Software Foundation,
15 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17 * Contact information: Zmanda Inc., 465 S Mathlida Ave, Suite 300
18 * Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
24 /* TODO: use glib chunk allocator */
26 /* NOTE TO IMPLEMENTERS:
28 * When adding a new attribute, make changes in the following places:
29 * - add the attribute to the XMsg struct in xmsg.h
30 * - add the attribute to the comments for the appropriate xmsg_types
31 * - free the attribute in xmsg_free.
44 XMsg *msg = g_new0(XMsg, 1);
47 msg->version = version;
49 /* messages hold a reference to the XferElement, to avoid dangling
51 g_object_ref((GObject *)elt);
60 /* unreference the source */
61 g_object_unref((GObject *)msg->elt);
63 /* and free any allocated attributes */
64 if (msg->repr) g_free(msg->repr);
65 if (msg->message) g_free(msg->message);
67 /* then free the XMsg itself */
75 if (!msg) return "(nil)"; /* better safe than sorry */
77 /* this just shows the "header" fields for now */
81 case XMSG_INFO: typ = "INFO"; break;
82 case XMSG_ERROR: typ = "ERROR"; break;
83 case XMSG_DONE: typ = "DONE"; break;
84 case XMSG_CANCEL: typ = "CANCEL"; break;
85 default: typ = "**UNKNOWN**"; break;
88 msg->repr = vstrallocf("<XMsg@%p type=XMSG_%s elt=%s version=%d>",
89 msg, typ, xfer_element_repr(msg->elt), msg->version);