2 * Copyright (C) 2004-2006, Eric Lund
3 * http://www.mvpmc.org/
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library 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 GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * rec_num.c - functions to manage recorder number structures. Mostly
22 * just allocating, freeing, and filling them out.
24 #include <sys/types.h>
32 #include <cmyth_local.h>
35 * cmyth_rec_num_destroy(cmyth_rec_num_t rn)
37 * Scope: PRIVATE (static)
41 * Destroy and release all storage associated with the recorder number
42 * structure 'rn'. This function should only ever be called by
43 * cmyth_rec_num_release(). All others should call
44 * cmyth_rec_num_release() to free rec_num structures.
51 cmyth_rec_num_destroy(cmyth_rec_num_t rn)
53 cmyth_dbg(CMYTH_DBG_DEBUG, "%s\n", __FUNCTION__);
57 if (rn->recnum_host) {
58 ref_release(rn->recnum_host);
63 * cmyth_rec_num_create(void)
69 * Create a recorder number structure.
73 * Success: A non-NULL cmyth_rec_num_t (this type is a pointer)
75 * Failure: A NULL cmyth_rec_num_t
78 cmyth_rec_num_create(void)
80 cmyth_rec_num_t ret = ref_alloc(sizeof(*ret));
82 cmyth_dbg(CMYTH_DBG_DEBUG, "%s\n", __FUNCTION__);
86 ref_set_destroy(ret, (ref_destroy_t)cmyth_rec_num_destroy);
88 ret->recnum_host = NULL;
95 * cmyth_rec_num_hold(cmyth_rec_num_t p)
101 * Take a new reference to a rec_num structure. Rec_Num structures
102 * are reference counted to facilitate caching of pointers to them.
103 * This allows a holder of a pointer to release their hold and trust
104 * that once the last reference is released the rec_num will be
105 * destroyed. This function is how one creates a new holder of a
106 * rec_num. This function always returns the pointer passed to it.
107 * While it cannot fail, if it is passed a NULL pointer, it will do
112 * Success: The value of 'p'
114 * Failure: There is no real failure case, but a NULL 'p' will result in a
118 cmyth_rec_num_hold(cmyth_rec_num_t p)
120 cmyth_dbg(CMYTH_DBG_DEBUG, "%s\n", __FUNCTION__);
125 * cmyth_rec_num_release(cmyth_rec_num_t p)
131 * Release a reference to a rec_num structure. Rec_Num structures
132 * are reference counted to facilitate caching of pointers to them.
133 * This allows a holder of a pointer to release their hold and trust
134 * that once the last reference is released the rec_num will be
135 * destroyed. This function is how one drops a reference to a
143 cmyth_rec_num_release(cmyth_rec_num_t p)
145 cmyth_dbg(CMYTH_DBG_DEBUG, "%s\n", __FUNCTION__);
150 * cmyth_rec_num_get(char *host,
151 * unsigned short port,
158 * Create a recorder number structure 'rn' using the values 'host',
163 * Success: A new cmyth_rec_num (this is a ppointer type)
168 cmyth_rec_num_get(char *host,
174 if ((ret = cmyth_rec_num_create()) == NULL) {
177 ret->recnum_host = ref_strdup(host);
178 if (!ret->recnum_host) {
182 ret->recnum_port = port;
188 * cmyth_rec_num_string(cmyth_rec_num_t rn)
194 * Compose a MythTV protocol string from a rec_num structure and
195 * return a pointer to a malloc'ed buffer containing the string.
199 * Success: A non-NULL malloc'ed character buffer pointer.
204 cmyth_rec_num_string(cmyth_rec_num_t rn)
206 unsigned len = sizeof("[]:[][]:[]");
214 if (!rn->recnum_host) {
217 sprintf(id, "%d", rn->recnum_id);
219 sprintf(port, "%d", rn->recnum_port);
221 len += strlen(rn->recnum_host);
222 ret = malloc((len + 1) * sizeof(char));
227 strcat(ret, "[]:[]");
228 strcat(ret, rn->recnum_host);
229 strcat(ret, "[]:[]");