mark PurpleImageClass as private
[pidgin-git.git] / libpurple / protocols / novell / nmrequest.c
blob8258064e3cbb45c6f12a1cc6dce911d4aac5fad7
1 /*
2 * nmrequest.c
4 * Copyright (c) 2004 Novell, Inc. All Rights Reserved.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
21 #include "nmrequest.h"
23 static int count = 0;
25 struct _NMRequest
27 int trans_id;
28 char *cmd;
29 int gmt;
30 gpointer data;
31 gpointer user_define;
32 nm_response_cb callback;
33 int ref_count;
34 NMERR_T ret_code;
37 NMRequest *nm_create_request(const char *cmd, int trans_id, int gmt, nm_response_cb cb,
38 gpointer resp_data, gpointer user_define)
40 NMRequest *req;
42 if (cmd == NULL)
43 return NULL;
45 req = g_new0(NMRequest, 1);
46 req->cmd = g_strdup(cmd);
47 req->trans_id = trans_id;
48 req->gmt = gmt;
49 req->callback = cb;
50 req->data = resp_data;
51 req->user_define = user_define;
52 req->ref_count = 1;
54 purple_debug_info("novell", "Creating NMRequest instance, total=%d\n", ++count);
56 return req;
59 void
60 nm_release_request(NMRequest * req)
62 if (req && (--req->ref_count == 0)) {
63 g_free(req->cmd);
64 g_free(req);
66 purple_debug_info("novell",
67 "Releasing NMRequest instance, total=%d\n", --count);
72 void
73 nm_request_add_ref(NMRequest * req)
75 if (req)
76 req->ref_count++;
79 void
80 nm_request_set_callback(NMRequest * req, nm_response_cb callback)
82 if (req)
83 req->callback = callback;
86 void
87 nm_request_set_data(NMRequest * req, gpointer data)
89 if (req)
90 req->data = data;
93 void
94 nm_request_set_user_define(NMRequest * req, gpointer user_define)
96 if (req)
97 req->user_define = user_define;
101 nm_request_get_trans_id(NMRequest * req)
103 if (req)
104 return req->trans_id;
105 else
106 return -1;
109 const char *
110 nm_request_get_cmd(NMRequest * req)
112 if (req == NULL)
113 return NULL;
115 return req->cmd;
118 gpointer
119 nm_request_get_data(NMRequest * req)
121 if (req == NULL)
122 return NULL;
124 return req->data;
127 gpointer
128 nm_request_get_user_define(NMRequest * req)
130 if (req == NULL)
131 return NULL;
133 return req->user_define;
136 nm_response_cb
137 nm_request_get_callback(NMRequest * req)
139 if (req == NULL)
140 return NULL;
142 return req->callback;
146 void
147 nm_request_set_ret_code(NMRequest * req, NMERR_T rc)
149 if (req)
150 req->ret_code = rc;
153 NMERR_T
154 nm_request_get_ret_code(NMRequest * req)
156 if (req)
157 return req->ret_code;
158 else
159 return (NMERR_T) - 1;