# HG changeset patch
# User morphbr
# Date 1174594925 0
# Node ID 5b33a92806a68c9470b2fda5443db43ba324c3d2
# Parent  ebaf693e005850228142156247e1ec4fc650c8a1
[svn r438] - Included gmyth_http_retrieve_job_status

diff -r ebaf693e0058 -r 5b33a92806a6 gmyth/debian/changelog
--- a/gmyth/debian/changelog	Thu Mar 22 19:37:16 2007 +0000
+++ b/gmyth/debian/changelog	Thu Mar 22 20:22:05 2007 +0000
@@ -1,7 +1,8 @@
 gmyth (0.2) unstable; urgency=low
 
-  * Included remote file transcoding
-  * Included recording profile management
+  * Included several http_requests in order to replace mysql queries (MythProtocol >= 33)
+  * Included remote file transcoding request and jobqueue request (need to apply patch)
+  * Included recording profile management (need to apply patch)
   * Several bug fixes
 
  -- Hallyson Melo <hallyson.melo@indt.org.br>  Mon,  5 Mar 2007 14:46:08 -0300
diff -r ebaf693e0058 -r 5b33a92806a6 gmyth/src/gmyth_http.c
--- a/gmyth/src/gmyth_http.c	Thu Mar 22 19:37:16 2007 +0000
+++ b/gmyth/src/gmyth_http.c	Thu Mar 22 20:22:05 2007 +0000
@@ -540,6 +540,85 @@
     return recorded;
 }
 
+
+
+/** Function to retrieve jobqueue status
+ *
+ */
+gint gmyth_http_retrieve_job_status (GMythBackendInfo *backend_info,
+                                          gint chanid, GTimeVal* start)
+{
+    gint status = 0;
+    gint count = 0;
+    gint temp_chanid = 0;
+    GTimeVal* temp_start = NULL;
+    int i;
+
+    xmlXPathObjectPtr result;
+    xmlNodeSetPtr nodeset;
+    xmlNodePtr node;
+    MemoryStruct chunk;
+
+    chunk.memory = NULL;
+    chunk.size = 0;
+
+    GString* command = g_string_new("");
+    g_string_printf(command, "GetStatus");
+
+    chunk = gmyth_http_request(backend_info, command);
+
+    if (chunk.memory != NULL)
+    {
+        xmlDocPtr doc = XMLParse(chunk.memory, strlen(chunk.memory));
+
+        result = getXPath((xmlChar*)"/Status/JobQueue", doc);
+        if (result)
+        {
+            nodeset = result->nodesetval;
+            node = nodeset->nodeTab[0];
+            sscanf((char *)xmlGetProp(node, (xmlChar*)"count"),\
+                                      "%d", &count);
+
+            if (count > 0)
+            {
+
+                // Get the first child
+                node = node->children->next;
+
+                for (i = 0; i < count; i++)
+                {
+
+                    sscanf((char *)xmlGetProp(node, (xmlChar*)"chanId"),\
+                           "%d", &temp_chanid);
+
+                    if (chanid == temp_chanid)
+                    {
+                        temp_start = gmyth_util_string_to_time_val \
+                            ((char *)xmlGetProp(node,(xmlChar *)"startTime"));
+
+                        if ( (temp_start->tv_sec == start->tv_sec) &&
+                             (temp_start->tv_usec == start->tv_usec) )
+                            sscanf((char *)xmlGetProp(node, (xmlChar*)"status"),\
+                                   "%d", &status);
+                    }
+
+                    // Escape "text" node
+                    node = node->next->next;
+                }
+            }
+
+        }
+
+        xmlXPathFreeObject (result);
+        free(chunk.memory);
+
+    }
+
+    return status;
+}
+
+
+
 /** Function to retrieve settings on the backend
  *
  * @param backend_info infos about the backend
@@ -845,10 +924,20 @@
       strlen(command->str) + 20;
 
     gchar *URL = (gchar *)g_malloc(sizeof(gchar)*size);
-    g_snprintf(URL, size, "http://%s:%d/Myth/%s", \
+    gchar *mid = (gchar *)g_malloc(sizeof(gchar)*6);
+
+    mid = "";
+
+    if ( g_ascii_strcasecmp(command->str, "GetStatus") && \
+         g_ascii_strcasecmp(command->str, "GetStatusHTML") )
+    {
+        mid = "Myth/";
+    }
+
+    g_snprintf(URL, size, "http://%s:%d/%s%s", \
            backend_info->hostname, \
            backend_info->status_port, \
-           command->str);
+           mid, command->str);
 
     CURL *curl_handle;
 
diff -r ebaf693e0058 -r 5b33a92806a6 gmyth/src/gmyth_http.h
--- a/gmyth/src/gmyth_http.h	Thu Mar 22 19:37:16 2007 +0000
+++ b/gmyth/src/gmyth_http.h	Thu Mar 22 20:22:05 2007 +0000
@@ -49,6 +49,25 @@
 
 #define MYTH_PORT_STATUS 6544
 
+#define JOB_UNKNOWN   0x0000
+#define JOB_QUEUED    0x0001
+#define JOB_PENDING   0x0002
+#define JOB_STARTING  0x0003
+#define JOB_RUNNING   0x0004
+#define JOB_STOPPING  0x0005
+#define JOB_PAUSED    0x0006
+#define JOB_RETRY     0x0007
+#define JOB_ERRORING  0x0008
+#define JOB_ABORTING  0x0009
+
+// JOB_DONE is a mask to indicate the job is done
+// whatever the status is
+#define JOB_DONE      0x0100
+#define JOB_FINISHED  0x0110
+#define JOB_ABORTED   0x0120
+#define JOB_ERRORED   0x0130
+#define JOB_CANCELLED 0x0140
+
 typedef struct _GMythRecorded_Recording GMythRecorded_Recording;
 typedef struct _GMythRecorded_Channel   GMythRecorded_Channel;
 typedef struct _GMythRecorded_Program   GMythRecorded_Program;
@@ -161,6 +180,9 @@
 };
 
 
+gint gmyth_http_retrieve_job_status (GMythBackendInfo *backend_info, \
+                                          gint chanid, GTimeVal* start);
+
 gchar* gmyth_http_retrieve_setting (GMythBackendInfo *backend_info,\
                                     gchar* key, gchar* hostname);
 
diff -r ebaf693e0058 -r 5b33a92806a6 gmyth/src/gmyth_transcoder.h
--- a/gmyth/src/gmyth_transcoder.h	Thu Mar 22 19:37:16 2007 +0000
+++ b/gmyth/src/gmyth_transcoder.h	Thu Mar 22 20:22:05 2007 +0000
@@ -50,6 +50,26 @@
 #define DATE_ISO 0
 #define DATE_FILE 1
 
+#define JOB_UNKNOWN   0x0000
+#define JOB_QUEUED    0x0001
+#define JOB_PENDING   0x0002
+#define JOB_STARTING  0x0003
+#define JOB_RUNNING   0x0004
+#define JOB_STOPPING  0x0005
+#define JOB_PAUSED    0x0006
+#define JOB_RETRY     0x0007
+#define JOB_ERRORING  0x0008
+#define JOB_ABORTING  0x0009
+
+// JOB_DONE is a mask to indicate the job is done
+// whatever the status
+#define JOB_DONE      0x0100
+#define JOB_FINISHED  0x0110
+#define JOB_ABORTED   0x0120
+#define JOB_ERRORED   0x0130
+#define JOB_CANCELLED 0x0140
+
+
 typedef struct _GMythTranscoder         GMythTranscoder;
 typedef struct _GMythTranscoderClass    GMythTranscoderClass;
 
diff -r ebaf693e0058 -r 5b33a92806a6 gmyth/tests/gmyth_test_http.c
--- a/gmyth/tests/gmyth_test_http.c	Thu Mar 22 19:37:16 2007 +0000
+++ b/gmyth/tests/gmyth_test_http.c	Thu Mar 22 20:22:05 2007 +0000
@@ -15,39 +15,43 @@
     gmyth_backend_info_set_port (backend_info, 6543);
     gmyth_backend_info_set_status_port (backend_info, 6544);
     
-    GTimeVal* start = gmyth_util_string_to_time_val("2006-01-01T00:00:00");
-    GTimeVal* end = gmyth_util_string_to_time_val("2007-03-10T00:00:00");
+    GTimeVal* start = gmyth_util_string_to_time_val("2007-03-19T17:00:00");
+    //GTimeVal* end = gmyth_util_string_to_time_val("2007-03-10T00:00:00");
 
-    GMythEpg epg;
-    epg  = gmyth_http_retrieve_epg(backend_info, start, end, 1000, 10000, "1");
+    //GMythEpg epg;
+    //epg  = gmyth_http_retrieve_epg(backend_info, start, end, 1000, 10000, "1");
 
     //if ( NULL == epg.channelList || g_slist_length( epg.channelList ) <= 0 )
     //	printf( "Channel list is empty!!!" );
  
-    GMythRecorded recorded;
-    recorded = gmyth_http_retrieve_recorded(backend_info);
+    //GMythRecorded recorded;
+    //recorded = gmyth_http_retrieve_recorded(backend_info);
 
-    GMythRecorded_Program* program = recorded.programList->data;
+    //GMythRecorded_Program* program = recorded.programList->data;
 
-    GSList* profiles = gmyth_http_retrieve_rec_profiles(backend_info, "Transcoders");
+    //GSList* profiles = gmyth_http_retrieve_rec_profiles(backend_info, "Transcoders");
 
-    GMythRecProfile* prof = profiles->data;
+    //GMythRecProfile* prof = profiles->data;
 
-    gchar* sett = gmyth_http_retrieve_setting(backend_info, "JobQueueTranscodeCommand", "wakko");	
+    //gchar* sett = gmyth_http_retrieve_setting(backend_info, "JobQueueTranscodeCommand", "wakko");	
 
-    GMythRecProfile* profile = gmyth_recprofile_new();
+    //GMythRecProfile* profile = gmyth_recprofile_new();
 
-    gmyth_recprofile_set_name(profile, "Teste");
-    gmyth_recprofile_set_group(profile, "Transcoders");
-    gmyth_recprofile_set_vcodec(profile, "MPEG-4");
-    gmyth_recprofile_set_acodec(profile, "MP3");
+    //gmyth_recprofile_set_name(profile, "Teste");
+    //gmyth_recprofile_set_group(profile, "Transcoders");
+    //gmyth_recprofile_set_vcodec(profile, "MPEG-4");
+    //gmyth_recprofile_set_acodec(profile, "MP3");
  
 
-    int teste = gmyth_http_create_rec_profile(backend_info, profile);
+    //int teste = gmyth_http_create_rec_profile(backend_info, profile);
 	
-    printf("Hello: %d\n", teste);
+    //printf("Hello: %d\n", teste);
 
-    int teste2 = gmyth_http_del_rec_profile(backend_info, 56);
+    //int teste2 = gmyth_http_del_rec_profile(backend_info, 56);
+
+    gint ret =  gmyth_http_retrieve_job_status(backend_info, 1000, start);
+    printf("Status: %d\n\n", ret);
+
 
     return 0;    
 }
diff -r ebaf693e0058 -r 5b33a92806a6 gmyth/tests/gmyth_test_transcode.c
--- a/gmyth/tests/gmyth_test_transcode.c	Thu Mar 22 19:37:16 2007 +0000
+++ b/gmyth/tests/gmyth_test_transcode.c	Thu Mar 22 20:22:05 2007 +0000
@@ -24,8 +24,8 @@
     transcode->cutlist = TRUE;
 
     //gmyth_transcoder_set_output (transcode, TRUE, "/tmp/teste.mp4");
-    gmyth_transcoder_set_filename (transcode, "1000_20070309160500.nuv");
-    //gmyth_transcoder_set_filename (transcode, "1000_20070319170000.nuv");
+    //gmyth_transcoder_set_filename (transcode, "1000_20070309160500.nuv");
+    gmyth_transcoder_set_filename (transcode, "1000_20070319170000.nuv");
     int teste = gmyth_jobqueue_add_job(transcode, "JOB_TRANSCODE");
 
     teste = gmyth_jobqueue_change_cmd(transcode, "STOP", "JOB_TRANSCODE");