File: gmyth_test_monitor_handler.c

package info (click to toggle)
gmyth 1%3A0.7.1-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 2,256 kB
  • ctags: 1,230
  • sloc: ansic: 11,662; sh: 8,936; makefile: 222
file content (145 lines) | stat: -rw-r--r-- 3,860 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include <glib-object.h>

#include "common.h"

#include <gmyth/gmyth_uri.h>
#include <gmyth/gmyth_backendinfo.h>
#include <gmyth/gmyth_livetv.h>
#include <gmyth/gmyth_monitor_handler.h>
#include <gmyth/gmyth_common.h>

#define URI_DEFAULT	"myth://192.168.3.165:6543/livetv?channel=9"

/**
 * The GObject signal handler function, from which all status messages 
 * from the Monitor Handler will be advertized, all time it receives
 * LiveTV status messages from the MythTV backend
 * 
 * @param monitor a GMythMonitorHandler instance
 * @param msg_code the MythTV's server numeric status code
 * @param message the message's string description
 * @param user_data pointer to the GMythLiveTV instance (NULL in the tests)
 */
static void
gmyth_livetv_monitor_signal_handler(GMythMonitorHandler * monitor,
                                    gint msg_code, gchar * message,
                                    gpointer user_data)
{
    g_debug
        ("LIVETV Signal handler ( msg = %s, code = %d, live_tv param = %s, user_data = %s )\n",
         message, msg_code, "NULL", user_data != NULL ? "" : "NULL");

}

/**
 * Starts the Monitor Handler to this GMythLiveTV session, in order
 * to receive the status messages from the MythTV's backend server 
 * 
 * @param live_tv the GMythLiveTV instance
 * 
 * @return <code>true</code> if the Monitor Handler start-up process
 * 	   had been concluded succcesfully 
 */
static          gboolean
gmyth_test_monitor_handler_start(GMythBackendInfo * backend_info,
                                 GMythMonitorHandler * *monitor)
{

    gboolean        res = TRUE;

    if (*monitor != NULL) {
        g_object_unref(*monitor);
        *monitor = NULL;
    }

    *monitor = gmyth_monitor_handler_new();

    res =
        gmyth_monitor_handler_open(*monitor,
                                   backend_info->hostname,
                                   backend_info->port);

    if (res == TRUE) {
        g_debug
            ("Connect MythTV Monitor event socket! Trying to start the message handler...");

        res = gmyth_monitor_handler_start(*monitor);

        if (res) {
            g_debug
                ("MythTV Monitor event socket connected and listening!");
            g_signal_connect(G_OBJECT(*monitor), "backend-events-handler",
                             (GCallback)
                             gmyth_livetv_monitor_signal_handler, NULL);
        } else {
            g_debug
                ("Problems when trying to start MythTV Monitor event socket!");
            goto error;
        }
    }

  error:
    return res;

}

static          gboolean
test_monitor_handler_setup(gchar * uri)
{
    gboolean        ret = TRUE;
    GMythMonitorHandler *monitor;

    if (NULL == uri)
        uri = g_strdup(URI_DEFAULT);

    GMythURI       *gmyth_uri = gmyth_uri_new_with_value(uri);

    GMythBackendInfo *backend_info = gmyth_backend_info_new_with_uri(uri);
    g_debug("uri = %s", uri);

    ret = gmyth_test_monitor_handler_start(backend_info, &monitor);

    if (ret == FALSE) {
        g_debug("MonitorHandler couldn't start!\n");
        goto init_failed;
    }

  init_failed:
    if (monitor != NULL)
        g_object_unref(monitor);

    if (gmyth_uri != NULL)
        g_object_unref(gmyth_uri);

    if (backend_info != NULL)
        g_object_unref(backend_info);

    return ret;

}

gint
main(gint args, const gchar ** argv)
{
    gboolean        ret;

    g_type_init();

    g_thread_init(NULL);

    fprintf(stdout, SYNC_STRING);
    fflush(NULL);
    getchar();

    if (args > 1)
        ret = test_monitor_handler_setup(argv[1]);
    else
        ret = test_monitor_handler_setup(NULL);

    if (!ret)
        g_debug("Error when running Monitor Handler setup test script!");
    else
        g_debug("MonitorHandler setup test script setup with success.");

    return (0);
}