[Redbutton-devel] SF.net SVN: redbutton: [306]
Brought to you by:
skilvington
|
From: <ski...@us...> - 2007-05-22 16:13:30
|
Revision: 306
http://svn.sourceforge.net/redbutton/?rev=306&view=rev
Author: skilvington
Date: 2007-05-22 09:13:24 -0700 (Tue, 22 May 2007)
Log Message:
-----------
SI_GetServiceIndex should return -1 if the service is unavailable
Modified Paths:
--------------
redbutton-browser/trunk/MHEGBackend.c
redbutton-browser/trunk/MHEGBackend.h
redbutton-browser/trunk/MHEGEngine.c
redbutton-browser/trunk/MHEGEngine.h
redbutton-browser/trunk/si.c
redbutton-download/trunk/channels.c
redbutton-download/trunk/channels.h
redbutton-download/trunk/command.c
Modified: redbutton-browser/trunk/MHEGBackend.c
===================================================================
--- redbutton-browser/trunk/MHEGBackend.c 2007-05-01 12:19:57 UTC (rev 305)
+++ redbutton-browser/trunk/MHEGBackend.c 2007-05-22 16:13:24 UTC (rev 306)
@@ -9,6 +9,8 @@
#include <netdb.h>
#include <arpa/inet.h>
#include <sys/socket.h>
+#include <sys/types.h>
+#include <sys/stat.h>
#include "MHEGEngine.h"
#include "si.h"
@@ -36,16 +38,18 @@
bool local_loadFile(MHEGBackend *, OctetString *, OctetString *);
FILE *local_openFile(MHEGBackend *, OctetString *);
void local_retune(MHEGBackend *, OctetString *);
+bool local_isServiceAvailable(MHEGBackend *, OctetString *);
static struct MHEGBackendFns local_backend_fns =
{
- local_checkContentRef, /* checkContentRef */
- local_loadFile, /* loadFile */
- local_openFile, /* openFile */
- open_stream, /* openStream */
- close_stream, /* closeStream */
- local_retune, /* retune */
- get_service_url, /* getServiceURL */
+ local_checkContentRef, /* checkContentRef */
+ local_loadFile, /* loadFile */
+ local_openFile, /* openFile */
+ open_stream, /* openStream */
+ close_stream, /* closeStream */
+ local_retune, /* retune */
+ get_service_url, /* getServiceURL */
+ local_isServiceAvailable, /* isServiceAvailable */
};
/* remote backend funcs */
@@ -53,16 +57,18 @@
bool remote_loadFile(MHEGBackend *, OctetString *, OctetString *);
FILE *remote_openFile(MHEGBackend *, OctetString *);
void remote_retune(MHEGBackend *, OctetString *);
+bool remote_isServiceAvailable(MHEGBackend *, OctetString *);
static struct MHEGBackendFns remote_backend_fns =
{
- remote_checkContentRef, /* checkContentRef */
- remote_loadFile, /* loadFile */
- remote_openFile, /* openFile */
- open_stream, /* openStream */
- close_stream, /* closeStream */
- remote_retune, /* retune */
- get_service_url, /* getServiceURL */
+ remote_checkContentRef, /* checkContentRef */
+ remote_loadFile, /* loadFile */
+ remote_openFile, /* openFile */
+ open_stream, /* openStream */
+ close_stream, /* closeStream */
+ remote_retune, /* retune */
+ get_service_url, /* getServiceURL */
+ remote_isServiceAvailable, /* isServiceAvailable */
};
/* public interface */
@@ -621,6 +627,52 @@
}
/*
+ * return true if we are able to receive the given service
+ * service should be in the form "dvb://<network_id>..<service_id>", eg "dvb://233a..4C80"
+ */
+
+bool
+local_isServiceAvailable(MHEGBackend *t, OctetString *service)
+{
+ unsigned int service_id;
+ char service_str[64];
+ char *slash;
+ int prefix_len;
+ char service_dir[PATH_MAX];
+ struct stat stats;
+ bool exists;
+
+ /* assert */
+ if(service->size < 6 || strncmp(service->data, "dvb://", 6) != 0)
+ fatal("local_isServiceAvailable: invalid service '%.*s'", service->size, service->data);
+
+ /* extract the service_id */
+ service_id = si_get_service_id(service);
+ snprintf(service_str, sizeof(service_str), "%u", service_id);
+
+ /*
+ * base_dir is: [path/to/services/]<service_id>
+ * so we just need to replace the last filename component with the new service_id
+ */
+ slash = strrchr(t->base_dir, '/');
+ if(slash == NULL)
+ {
+ /* no preceeding path */
+ snprintf(service_dir, sizeof(service_dir), "%s", service_str);
+ }
+ else
+ {
+ prefix_len = (slash - t->base_dir) + 1;
+ snprintf(service_dir, sizeof(service_dir), "%.*s%s", prefix_len, t->base_dir, service_str);
+ }
+
+ /* see if the directory for the service exists */
+ exists = (stat(service_dir, &stats) == 0);
+
+ return exists;
+}
+
+/*
* remote routines
*/
@@ -781,3 +833,29 @@
return;
}
+/*
+ * return true if we are able to receive the given service
+ * service should be in the form "dvb://<network_id>..<service_id>", eg "dvb://233a..4C80"
+ */
+
+bool
+remote_isServiceAvailable(MHEGBackend *t, OctetString *service)
+{
+ char cmd[128];
+ FILE *sock;
+ bool available = true;
+
+ /* assert */
+ if(service->size < 6 || strncmp(service->data, "dvb://", 6) != 0)
+ fatal("remote_isServiceAvailable: invalid service '%.*s'", service->size, service->data);
+
+ snprintf(cmd, sizeof(cmd), "available %u\n", si_get_service_id(service));
+
+ if((sock = remote_command(t, true, cmd)) == NULL
+ || remote_response(sock) != BACKEND_RESPONSE_OK)
+ {
+ available = false;
+ }
+
+ return available;
+}
Modified: redbutton-browser/trunk/MHEGBackend.h
===================================================================
--- redbutton-browser/trunk/MHEGBackend.h 2007-05-01 12:19:57 UTC (rev 305)
+++ redbutton-browser/trunk/MHEGBackend.h 2007-05-22 16:13:24 UTC (rev 306)
@@ -44,6 +44,8 @@
void (*retune)(struct MHEGBackend *, OctetString *);
/* return a dvb:// URL for the service we are currently downloading the carousel from */
const OctetString *(*getServiceURL)(struct MHEGBackend *);
+ /* return true if the engine is able to receive the given service (dvb:// URL format) */
+ bool (*isServiceAvailable)(struct MHEGBackend *, OctetString *);
} *fns;
} MHEGBackend;
Modified: redbutton-browser/trunk/MHEGEngine.c
===================================================================
--- redbutton-browser/trunk/MHEGEngine.c 2007-05-01 12:19:57 UTC (rev 305)
+++ redbutton-browser/trunk/MHEGEngine.c 2007-05-22 16:13:24 UTC (rev 306)
@@ -1476,6 +1476,18 @@
}
/*
+ * return true if the engine is able to receive the given service
+ * service should be in the form "dvb://<network_id>..<service_id>", eg "dvb://233a..4C80"
+ */
+
+bool
+MHEGEngine_isServiceAvailable(OctetString *service)
+{
+ /* ask the backend */
+ return (*(engine.backend.fns->isServiceAvailable))(&engine.backend, service);
+}
+
+/*
* returns the absolute group ID, ie it always starts with "~//"
* returns a ptr to static string that will be overwritten by the next call to this routine
* section 8.3.2 of the UK MHEG Profile says the filename prefixes are:
Modified: redbutton-browser/trunk/MHEGEngine.h
===================================================================
--- redbutton-browser/trunk/MHEGEngine.h 2007-05-01 12:19:57 UTC (rev 305)
+++ redbutton-browser/trunk/MHEGEngine.h 2007-05-22 16:13:24 UTC (rev 306)
@@ -249,6 +249,8 @@
const OctetString *MHEGEngine_getRecSvcDef(void);
const OctetString *MHEGEngine_getRecSvcCur(void);
+bool MHEGEngine_isServiceAvailable(OctetString *);
+
char *MHEGEngine_absoluteFilename(OctetString *);
/* convert PNG to internal format */
Modified: redbutton-browser/trunk/si.c
===================================================================
--- redbutton-browser/trunk/si.c 2007-05-01 12:19:57 UTC (rev 305)
+++ redbutton-browser/trunk/si.c 2007-05-22 16:13:24 UTC (rev 306)
@@ -21,6 +21,8 @@
* "rec://svc/lcn/X" - use logical channel number X (eg 1 for BBC1, 3 for ITV1, etc)
*
* we resolve whatever we are given to a dvb:// format URL and store that
+ *
+ * returns -1 if the backend says the given service is not available
*/
int
@@ -54,6 +56,10 @@
if(OctetString_cmp(ref, &si_channel[i]) == 0)
return i;
+ /* does the backend say it is available */
+ if(!MHEGEngine_isServiceAvailable(ref))
+ return -1;
+
/* add it to the list */
si_max_index ++;
si_channel = safe_realloc(si_channel, (si_max_index + 1) * sizeof(OctetString));
Modified: redbutton-download/trunk/channels.c
===================================================================
--- redbutton-download/trunk/channels.c 2007-05-01 12:19:57 UTC (rev 305)
+++ redbutton-download/trunk/channels.c 2007-05-22 16:13:24 UTC (rev 306)
@@ -610,4 +610,30 @@
return true;
}
+/*
+ * returns true if service_id is listed in the channels file
+ */
+bool
+service_available(uint16_t service_id)
+{
+ char line[1024];
+ char *p;
+ unsigned long id;
+
+ rewind(_channels);
+
+ while(!feof(_channels))
+ {
+ /* service_id is the last field for all channels.conf file formats */
+ if(fgets(line, sizeof(line), _channels) == NULL
+ || (p = rindex(line, ':')) == NULL)
+ continue;
+ id = strtoul(p + 1, NULL, 0);
+ if(id == service_id)
+ return true;
+ }
+
+ return false;
+}
+
Modified: redbutton-download/trunk/channels.h
===================================================================
--- redbutton-download/trunk/channels.h 2007-05-01 12:19:57 UTC (rev 305)
+++ redbutton-download/trunk/channels.h 2007-05-22 16:13:24 UTC (rev 306)
@@ -32,5 +32,7 @@
bool tune_service_id(unsigned int, unsigned int, uint16_t);
+bool service_available(uint16_t);
+
#endif /* __CHANNELS_H__ */
Modified: redbutton-download/trunk/command.c
===================================================================
--- redbutton-download/trunk/command.c 2007-05-01 12:19:57 UTC (rev 305)
+++ redbutton-download/trunk/command.c 2007-05-22 16:13:24 UTC (rev 306)
@@ -18,6 +18,7 @@
#include "assoc.h"
#include "fs.h"
#include "stream.h"
+#include "channels.h"
#include "utils.h"
/* max number of args that can be passed to a command (arbitrary) */
@@ -27,6 +28,7 @@
bool cmd_assoc(struct listen_data *, FILE *, int, char **);
bool cmd_ademux(struct listen_data *, FILE *, int, char **);
bool cmd_astream(struct listen_data *, FILE *, int, char **);
+bool cmd_available(struct listen_data *, FILE *, int, char **);
bool cmd_avdemux(struct listen_data *, FILE *, int, char **);
bool cmd_avstream(struct listen_data *, FILE *, int, char **);
bool cmd_check(struct listen_data *, FILE *, int, char **);
@@ -49,6 +51,7 @@
{ "assoc", "", cmd_assoc, "List component tag to PID mappings" },
{ "ademux", "[<ServiceID>] <ComponentTag>", cmd_ademux, "Demux the given audio component tag" },
{ "astream", "[<ServiceID>] <ComponentTag>", cmd_astream, "Stream the given audio component tag" },
+ { "available", "<ServiceID>", cmd_available, "Return OK if the ServiceID is available" },
{ "avdemux", "[<ServiceID>] <AudioTag> <VideoTag>", cmd_avdemux, "Demux the given audio and video component tags" },
{ "avstream", "[<ServiceID>] <AudioTag> <VideoTag>", cmd_avstream, "Stream the given audio and video component tags" },
{ "check", "<ContentReference>", cmd_check, "Check if the given file exists on the carousel" },
@@ -670,6 +673,28 @@
}
/*
+ * available <ServiceID>
+ * returns 200 OK if ServiceID is listed in the channels.conf file
+ */
+
+bool
+cmd_available(struct listen_data *listen_data, FILE *client, int argc, char *argv[])
+{
+ unsigned int service_id;
+
+ CHECK_USAGE(2, "available <ServiceID>");
+
+ service_id = strtoul(argv[1], NULL, 0);
+
+ if(service_available(service_id))
+ SEND_RESPONSE(200, "OK");
+ else
+ SEND_RESPONSE(404, "Not Found");
+
+ return false;
+}
+
+/*
* check <ContentReference>
* check if the given file is on the carousel
* ContentReference should be absolute, ie start with "~//"
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|