Send commitlog mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://lists.openmoko.org/mailman/listinfo/commitlog
or, via email, send a message with subject or body 'help' to
        [EMAIL PROTECTED]

You can reach the person managing the list at
        [EMAIL PROTECTED]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of commitlog digest..."
Today's Topics:

   1. r2026 - trunk/src/host/qemu-neo1973/gnokiigsm
      ([EMAIL PROTECTED])
   2. r2027 - in
      trunk/src/target/OM-2007/applications/openmoko-rssreader: . src
      tests ([EMAIL PROTECTED])
   3. r2028 - in
      trunk/src/target/OM-2007/applications/openmoko-rssreader: . src
      ([EMAIL PROTECTED])
--- Begin Message ---
Author: andrew
Date: 2007-05-18 22:52:47 +0200 (Fri, 18 May 2007)
New Revision: 2026

Modified:
   trunk/src/host/qemu-neo1973/gnokiigsm/at-emulator.c
   trunk/src/host/qemu-neo1973/gnokiigsm/data.h
Log:
Add more dummy AT+C commands in GSM modem.


Modified: trunk/src/host/qemu-neo1973/gnokiigsm/at-emulator.c
===================================================================
--- trunk/src/host/qemu-neo1973/gnokiigsm/at-emulator.c 2007-05-18 20:48:49 UTC 
(rev 2025)
+++ trunk/src/host/qemu-neo1973/gnokiigsm/at-emulator.c 2007-05-18 20:52:47 UTC 
(rev 2026)
@@ -331,7 +331,253 @@
        }
 }
 
+struct gn_atem_op {
+       char *op;
+       int writable;
+       enum {
+               gn_var_string,  /* "A","B","C" */
+               gn_var_bool,    /* 0,1 */
+               gn_var_numbers, /* (1-5),(9-20) */
+       } type;
+       char *default_val;
+       char *string_val[];
+};
 
+bool   gn_atem_parse_option(char *buf, struct gn_atem_op *op, char *val)
+{
+       char    buffer[MAX_LINE_LENGTH], **strval;
+       int     len;
+       if (buf[0] == 0 || (buf[0] == '?' && buf[1] == 0)) {
+               gsprintf(buffer, MAX_LINE_LENGTH, "%s: %s\r\n", op->op, val);
+               gn_atem_string_out(buffer);
+               return (false);
+       }
+
+       if (*buf++ != '=')
+               return (true);
+       if (!strcasecmp(buf, "?")) {
+               len = gsprintf(buffer, MAX_LINE_LENGTH, "%s: ", op->op);
+               switch (op->type) {
+               case gn_var_string:
+                       strval = op->string_val;
+                       len += gsprintf(buffer + len,
+                                       MAX_LINE_LENGTH - len,
+                                       "\"%s\"", *strval++);
+                       while (*strval)
+                               len += gsprintf(buffer + len,
+                                               MAX_LINE_LENGTH - len,
+                                               ",\"%s\"", *strval++);
+                       break;
+
+               case gn_var_numbers:
+                       strval = op->string_val;
+                       len += gsprintf(buffer + len,
+                                       MAX_LINE_LENGTH - len,
+                                       "\"%s\"", *strval++);
+                       /* TODO */
+                       break;
+
+               case gn_var_bool:
+                       len += gsprintf(buffer + len,
+                                       MAX_LINE_LENGTH - len, "(0,1)");
+                       break;
+               }
+               gsprintf(buffer + len, MAX_LINE_LENGTH - len, "\r\n");
+               return (false);
+       }
+
+       if (!op->writable)
+               return (true);
+
+       switch (op->type) {
+       case gn_var_string:
+               for (strval = op->string_val; *strval; strval++)
+                       if (!strcasecmp(buf, *strval)) {
+                               gsprintf(val, MAX_LINE_LENGTH,
+                                               "\"%s\"", *strval);
+                               return (false);
+                       }
+               break;
+
+       case gn_var_bool:
+               if (!strcasecmp(buf, "0") || !strcasecmp(buf, "1")) {
+                       strncpy(val, buf, MAX_LINE_LENGTH);
+                       return (false);
+               }
+               break;
+
+       default:
+               break;
+       }
+
+       return (true);
+}
+
+static struct gn_atem_op gn_atem_op_cscs = {
+       .op             = "+CSCS",
+       .writable       = 1,
+       .type           = gn_var_string,
+       .default_val    = "IRA",
+       .string_val     = {
+               "GSM", "IRA", "PCCP437", "PCDN", "8859-1", "HEX", "UCS2", 0,
+       },
+};
+
+static struct gn_atem_op gn_atem_op_cmux = {
+       .op             = "+CMUX",
+       .writable       = 1,
+       .type           = gn_var_numbers,
+       .default_val    = "1,0,1,10,1,0,2,1,1",
+       .string_val     = {
+               "(1),(0),(1-5),(10-100),(1-255),(0-100),(2-255),(1-255),(1-7)",
+       },
+};
+
+static struct gn_atem_op gn_atem_op_ws46 = {
+       .op             = "+WS46",
+       .writable       = 1,
+       .type           = gn_var_numbers,
+       .default_val    = "12",
+       .string_val     = {
+               "(12)",
+       },
+};
+
+static struct gn_atem_op gn_atem_op_csta = {
+       .op             = "+CSTA",
+       .writable       = 1,
+       .type           = gn_var_numbers,
+       .default_val    = "129",
+       .string_val     = {
+               "(129,145)",
+       },
+};
+
+static struct gn_atem_op gn_atem_op_cmod = {
+       .op             = "+CMOD",
+       .writable       = 1,
+       .type           = gn_var_numbers,
+       .default_val    = "0",
+       .string_val     = {
+               "(0-3)",
+       },
+};
+
+static struct gn_atem_op gn_atem_op_cbst = {
+       .op             = "+CBST",
+       .writable       = 0,
+       .type           = gn_var_numbers,
+       .default_val    = "7,0,1",
+       .string_val     = {
+               "(0-7,12,14,65,66,68,70,71,75),(0),(0-3)",
+       },
+};
+
+static struct gn_atem_op gn_atem_op_crlp = {
+       .op             = "+CRLP",
+       .writable       = 1,
+       .type           = gn_var_numbers,
+       .default_val    = "61,61,48,6",
+       .string_val     = {
+               "(0-61),(0-61),(39-255),(1-255)",
+       },
+};
+
+static struct gn_atem_op gn_atem_op_cr = {
+       .op             = "+CR",
+       .writable       = 1,
+       .type           = gn_var_numbers,
+       .default_val    = "0",
+       .string_val     = {
+               "(0,1)",
+       },
+};
+
+static struct gn_atem_op gn_atem_op_crc = {
+       .op             = "+CRC",
+       .writable       = 1,
+       .type           = gn_var_bool,
+       .default_val    = "0",
+};
+
+static struct gn_atem_op gn_atem_op_csns = {
+       .op             = "+CSNS",
+       .writable       = 1,
+       .type           = gn_var_numbers,
+       .default_val    = "0",
+       .string_val     = {
+               "(0-7)",
+       },
+};
+
+static struct gn_atem_op gn_atem_op_creg = {
+       .op             = "+CREG",
+       .writable       = 1,
+       .type           = gn_var_numbers,
+       .default_val    = "0,0",
+       .string_val     = {
+               "(0-2)",
+       },
+};
+
+static struct gn_atem_op gn_atem_op_cops = {
+       .op             = "+COPS",
+       .writable       = 1,
+       .type           = gn_var_bool,
+       .default_val    = "0",
+};
+
+static struct gn_atem_op gn_atem_op_cpas = {
+       .op             = "+CPAS",
+       .writable       = 1,
+       .type           = gn_var_numbers,
+       .default_val    = "0",
+       .string_val     = {
+               "(0-5)",
+       },
+};
+
+static struct gn_atem_op gn_atem_op_cfun = {
+       .op             = "+CFUN",
+       .writable       = 1,
+       .type           = gn_var_numbers,
+       .default_val    = "1",
+       .string_val     = {
+               "(0,1,4),(0)",
+       },
+};
+
+static struct gn_atem_op gn_atem_op_cbc = {
+       .op             = "+CBC",
+       .writable       = 1,
+       .type           = gn_var_numbers,
+       .default_val    = "0,0",
+       .string_val     = {
+               "(0-3),(0-100)",
+       },
+};
+
+static struct gn_atem_op gn_atem_op_band = {
+       .op             = "%BAND",
+       .writable       = 1,
+       .type           = gn_var_numbers,
+       .default_val    = "0",
+       .string_val     = {
+               "(0-1),(1-31)",
+       },
+};
+
+static struct gn_atem_op gn_atem_op_cssn = {
+       .op             = "CSSN",
+       .writable       = 1,
+       .type           = gn_var_numbers,
+       .default_val    = "0,0",
+       .string_val     = {
+               "(0,1),(0,1)",
+       },
+};
+
+
 /* Parser for standard AT commands.  cmd_buffer must be null terminated. */
 void   gn_atem_at_parse(char *cmd_buffer)
 {
@@ -558,6 +804,14 @@
                /* + is the precursor to another set of commands */
                case '+':
                        buf++;
+
+                       /* AT+WS46 is wireless network selection */
+                       if (strncasecmp(buf, "WS46", 3) == 0) {
+                               if (!gn_atem_parse_option(buf + 4,
+                                               &gn_atem_op_ws46, data.ws46))
+                                       break;
+                       }
+
                        switch (toupper(*buf)) {
                        case 'C':
                                buf++;
@@ -593,6 +847,17 @@
                        }
                        break;
 
+               /* % is the precursor to another set of commands */
+               case '%':
+                       buf++;
+                       if (strncasecmp(buf, "BAND", 3) == 0) {
+                               if (!gn_atem_parse_option(buf + 4,
+                                               &gn_atem_op_band, data.band))
+                                       break;
+                       }
+                       gn_atem_modem_result(MR_ERROR);
+                       return;
+
                default:
                        gn_atem_modem_result(MR_ERROR);
                        return;
@@ -1011,6 +1276,105 @@
                return (false);
        }
 
+       /* AT+CSCS is character set selection */
+       if (strncasecmp(*buf, "SCS", 3) == 0) {
+               return gn_atem_parse_option(buf[0] + 3,
+                               &gn_atem_op_cscs, data.cscs);
+       }
+
+       /* AT+CIMI is international mobile subscriber identity */
+       if (strcasecmp(*buf, "IMI") == 0) {
+               gn_atem_string_out("QEMU_IMSI\r\n");
+               return (false);
+       }
+
+       /* AT+CMUX is multiplexing mode */
+       if (strncasecmp(*buf, "MUX", 3) == 0) {
+               return gn_atem_parse_option(buf[0] + 3,
+                               &gn_atem_op_cmux, data.cmux);
+       }
+
+       /* AT+CSTA is address type selection */
+       if (strncasecmp(*buf, "STA", 3) == 0) {
+               return gn_atem_parse_option(buf[0] + 3,
+                               &gn_atem_op_csta, data.csta);
+       }
+
+       /* AT+CMOD is call mode */
+       if (strncasecmp(*buf, "MOD", 3) == 0) {
+               return gn_atem_parse_option(buf[0] + 3,
+                               &gn_atem_op_cmod, data.cmod);
+       }
+
+       /* AT+CBST is bearer service type */
+       if (strncasecmp(*buf, "BST", 3) == 0) {
+               return gn_atem_parse_option(buf[0] + 3,
+                               &gn_atem_op_cbst, data.cbst);
+       }
+
+       /* AT+CRLP is radio link protocol */
+       if (strncasecmp(*buf, "RLP", 3) == 0) {
+               return gn_atem_parse_option(buf[0] + 3,
+                               &gn_atem_op_crlp, data.crlp);
+       }
+
+       /* AT+CR is reporting control */
+       if (strncasecmp(*buf, "R", 1) == 0) {
+               return gn_atem_parse_option(buf[0] + 1,
+                               &gn_atem_op_cr, data.cr);
+       }
+
+       /* AT+CEER is extended error report */
+       if (strncasecmp(*buf, "EER", 3) == 0) {
+               gn_atem_string_out("+CEER: 0,0,5,16,normal call clearing\r\n");
+               return (false);
+       }
+
+       /* AT+CRC is cellular result codes */
+       if (strncasecmp(*buf, "RC", 2) == 0) {
+               return gn_atem_parse_option(buf[0] + 2,
+                               &gn_atem_op_crc, data.crc);
+       }
+
+       /* AT+CSNS is single numbering scheme */
+       if (strncasecmp(*buf, "SNS", 3) == 0) {
+               return gn_atem_parse_option(buf[0] + 3,
+                               &gn_atem_op_csns, data.csns);
+       }
+
+       /* AT+CREG is network registration */
+       if (strncasecmp(*buf, "REG", 3) == 0) {
+               return gn_atem_parse_option(buf[0] + 3,
+                               &gn_atem_op_creg, data.creg);
+       }
+
+       /* AT+COPS is PLMN selection */
+       if (strncasecmp(*buf, "OPS", 3) == 0) {
+               return gn_atem_parse_option(buf[0] + 3,
+                               &gn_atem_op_cops, data.cops);
+       }
+
+       /* AT+CPAS is phone activity status */
+       if (strncasecmp(*buf, "PAS", 3) == 0) {
+               return gn_atem_parse_option(buf[0] + 3,
+                               &gn_atem_op_cpas, data.cpas);
+       }
+
+       /* AT+CFUN is phone functionality */
+       if (strncasecmp(*buf, "FUN", 3) == 0) {
+               return gn_atem_parse_option(buf[0] + 3,
+                               &gn_atem_op_cfun, data.cfun);
+       }
+
+       if (strncasecmp(*buf, "BC", 2) == 0) {
+               return gn_atem_parse_option(buf[0] + 2,
+                               &gn_atem_op_cbc, data.cbc);
+       }
+       if (strncasecmp(*buf, "CSSN", 2) == 0) {
+               return gn_atem_parse_option(buf[0] + 2,
+                               &gn_atem_op_cssn, data.cssn);
+       }
+
        return (true);
 }
 

Modified: trunk/src/host/qemu-neo1973/gnokiigsm/data.h
===================================================================
--- trunk/src/host/qemu-neo1973/gnokiigsm/data.h        2007-05-18 20:48:49 UTC 
(rev 2025)
+++ trunk/src/host/qemu-neo1973/gnokiigsm/data.h        2007-05-18 20:52:47 UTC 
(rev 2026)
@@ -45,7 +45,7 @@
 } gn_phone_model;
 
 /* For all 'AT+XXXX=?' commands */
-typedef char gn_choice[10];
+typedef char gn_choice[256];
 
 /* This is a generic holder for high level information - eg a gn_bmp */
 typedef struct {
@@ -115,6 +115,8 @@
        gn_choice cbst;
        gn_choice crlp;
        gn_choice cr;
+       gn_choice crc;
+       gn_choice cmod;
        gn_choice csns;
        gn_choice creg;
        gn_choice cpas;




--- End Message ---
--- Begin Message ---
Author: zecke
Date: 2007-05-18 23:32:25 +0200 (Fri, 18 May 2007)
New Revision: 2027

Added:
   trunk/src/target/OM-2007/applications/openmoko-rssreader/tests/cache_test.c
Modified:
   trunk/src/target/OM-2007/applications/openmoko-rssreader/ChangeLog
   trunk/src/target/OM-2007/applications/openmoko-rssreader/src/moko_cache.c
   trunk/src/target/OM-2007/applications/openmoko-rssreader/src/moko_cache.h
   trunk/src/target/OM-2007/applications/openmoko-rssreader/tests/
   trunk/src/target/OM-2007/applications/openmoko-rssreader/tests/Makefile.am
Log:
2007-05-18  Holger Freyther  <[EMAIL PROTECTED]>

        Test the cache implementation

        * src/moko_cache.c:
        (moko_cache_create_dirs): Fix the g_file_test logic
        (object_name_to_file_name): replace the tile as well (~)
        (moko_cache_write_object): use g_set_file_contents to gain atomic
        writes
        * src/moko_cache.h: Update write prototype to gain a GError**
        * tests/Makefile.am:
        * tests/cache_test.c: Added.



Modified: trunk/src/target/OM-2007/applications/openmoko-rssreader/ChangeLog
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-rssreader/ChangeLog  
2007-05-18 20:52:47 UTC (rev 2026)
+++ trunk/src/target/OM-2007/applications/openmoko-rssreader/ChangeLog  
2007-05-18 21:32:25 UTC (rev 2027)
@@ -1,6 +1,19 @@
+2007-05-18  Holger Freyther  <[EMAIL PROTECTED]>
+
+        Test the cache implementation
+
+        * src/moko_cache.c:
+        (moko_cache_create_dirs): Fix the g_file_test logic
+        (object_name_to_file_name): replace the tile as well (~)
+        (moko_cache_write_object): use g_set_file_contents to gain atomic
+        writes
+        * src/moko_cache.h: Update write prototype to gain a GError**
+        * tests/Makefile.am:
+        * tests/cache_test.c: Added.
+
 2007-05-03  Holger Freyther  <[EMAIL PROTECTED]>
 
-        Start implementing the test (untested)
+        Start implementing the cache (untested)
 
         * src/moko_cache.c:
         (moko_cache_create_dirs): Make sure to create the dir. Somehow there

Modified: 
trunk/src/target/OM-2007/applications/openmoko-rssreader/src/moko_cache.c
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-rssreader/src/moko_cache.c   
2007-05-18 20:52:47 UTC (rev 2026)
+++ trunk/src/target/OM-2007/applications/openmoko-rssreader/src/moko_cache.c   
2007-05-18 21:32:25 UTC (rev 2027)
@@ -55,13 +55,18 @@
 moko_cache_create_dirs (gchar *cache_name)
 {
     gchar *path = g_build_path (G_DIR_SEPARATOR_S, g_get_home_dir (), 
CACHE_NAME, NULL);
-    if (g_file_test (path, G_FILE_TEST_EXISTS))
+    if (!g_file_test (path, G_FILE_TEST_EXISTS)) {
+        g_debug ("Trying to create dir '%s'\n", path);
         g_mkdir (path, 0700);
+    }
+
     g_free (path);
 
     path = g_build_path (G_DIR_SEPARATOR_S, g_get_home_dir (), CACHE_NAME, 
cache_name, NULL);
-    if (g_file_test (path, G_FILE_TEST_EXISTS))
+    if (!g_file_test (path, G_FILE_TEST_EXISTS)) {
+        g_debug ("Trying to create app cache dir '%s'\n", path);
         g_mkdir (path, 0700);
+    }
     g_free (path);
     
 }
@@ -85,7 +90,7 @@
     gchar *result = g_strdup (file_name);
     const int l = strlen(result);
     for (int i = 0; i < l; ++i)
-        if ( result[i] == '/' || result[i] == ':' || result[i] == '.' )
+        if ( result[i] == '/' || result[i] == ':' || result[i] == '.' || 
result[i] == '~' )
             result[i] = '_';
 
     return result;
@@ -141,7 +146,7 @@
 }
 
 gint
-moko_cache_write_object (MokoCache *self, gchar *object_name, gchar *content, 
gsize size)
+moko_cache_write_object (MokoCache *self, gchar *object_name, gchar *content, 
gsize size, GError **g_error)
 {
     int error = MOKO_CACHE_WRITE_SUCCESS;
     size = size == -1 ? strlen(content) : size;
@@ -150,18 +155,10 @@
     gchar *file_name = object_name_to_file_name (object_name);
     gchar *path = moko_cache_create_path (self->cache_name, file_name);
 
-    int fd = g_open (path, O_WRONLY|O_TRUNC, 0700);
-    if ( fd < 0 ) {
+    gboolean result = g_file_set_contents (path, content, size, g_error);
+    if (!result )
         error = MOKO_CACHE_WRITE_UNKNOWN_ERROR;
-        goto error_path;
-    }
 
-    if ( write (fd, content, size) < 0 ) {
-        error = MOKO_CACHE_WRITE_UNKNOWN_ERROR;
-        goto error_path;
-    }
-
-error_path:
     g_free (path);
     g_free (file_name);
     return error;

Modified: 
trunk/src/target/OM-2007/applications/openmoko-rssreader/src/moko_cache.h
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-rssreader/src/moko_cache.h   
2007-05-18 20:52:47 UTC (rev 2026)
+++ trunk/src/target/OM-2007/applications/openmoko-rssreader/src/moko_cache.h   
2007-05-18 21:32:25 UTC (rev 2027)
@@ -71,7 +71,7 @@
 gint          moko_cache_get_allowed_size (MokoCache *self);
 gint          moko_cache_get_utilized_size(MokoCache *self);
 
-gint          moko_cache_write_object (MokoCache *self, gchar *object_name, 
gchar *content, gsize size);
+gint          moko_cache_write_object (MokoCache *self, gchar *object_name, 
gchar *content, gsize size, GError** error);
 gchar*        moko_cache_read_object  (MokoCache *self, gchar *object_name, 
gsize *size);
 
 /**
@@ -95,10 +95,12 @@
  */
 
 /**
- * \fn moko_cache_write_object (MokoCache *self, gchar *object_name, gchar 
*content, guint size);
+ * \fn moko_cache_write_object (MokoCache *self, gchar *object_name, gchar 
*content, guint size, GError** error);
  * @param object_name The name of the object. E.g. http://www.heise.de/atom.xml
  * @param content     The actual content to be written to the cache
  * @param size        The size of the content. If it is -1 strlen will be used 
to determine the size
+ * @param error       The error containing a nice string.
+ * @return one of the MokoCacheWriteResult
  */
 
 /**


Property changes on: 
trunk/src/target/OM-2007/applications/openmoko-rssreader/tests
___________________________________________________________________
Name: svn:ignore
   - Makefile
Makefile.in
.deps
.libs
datetest
*.swp

   + Makefile
Makefile.in
.deps
.libs
datetest
*.swp
*.swo
cachetest


Modified: 
trunk/src/target/OM-2007/applications/openmoko-rssreader/tests/Makefile.am
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-rssreader/tests/Makefile.am  
2007-05-18 20:52:47 UTC (rev 2026)
+++ trunk/src/target/OM-2007/applications/openmoko-rssreader/tests/Makefile.am  
2007-05-18 21:32:25 UTC (rev 2027)
@@ -2,11 +2,16 @@
 INCLUDES  = -I$(top_srcdir)/src
 
 if ENABLE_TESTING
-TESTS = datetest
-check_PROGRAMS = datetest
+TESTS = datetest cachetest
+check_PROGRAMS = datetest cachetest
 endif
 
 datatest_INCLUDES = @CHECK_CFLAGS@
 datetest_SOURCES  = date_test.c ../src/rfcdate.c
 datetest_LIBS     = @CHECK_LIBS@
 datetest_LDFLAGS  = -lcheck @GCOV_LDFLAGS@ @OPENMOKO_LIBS@
+
+cachetest_INCLUDES = @CHECK_CFLAGS@
+cachetest_SOURCES  = cache_test.c ../src/moko_cache.c
+cachetest_LIBS     = @CHECK_LIBS@
+cachetest_LDFLAGS  = -lcheck @GCOV_LDFLAGS@ @OPENMOKO_LIBS@

Added: 
trunk/src/target/OM-2007/applications/openmoko-rssreader/tests/cache_test.c
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-rssreader/tests/cache_test.c 
2007-05-18 20:52:47 UTC (rev 2026)
+++ trunk/src/target/OM-2007/applications/openmoko-rssreader/tests/cache_test.c 
2007-05-18 21:32:25 UTC (rev 2027)
@@ -0,0 +1,104 @@
+#include <check.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <glib.h>
+#include <string.h>
+#include "rfcdate.h"
+
+#include "moko_cache.h"
+
+START_TEST (test_create_cache)
+{
+    GObject *cache = moko_cache_new ("moko-cache-test");
+    g_object_unref (cache);
+}
+END_TEST
+
+/*
+ * test error handling
+ */
+START_TEST (test_read_empty_cache)
+{
+    GObject *cache = moko_cache_new ("moko-cache-test");
+    fail_unless (cache != NULL, "Creating failed?");
+
+    gsize size;
+    gchar *cache_data = moko_cache_read_object (MOKO_CACHE(cache), 
"http://www.openembedded.org/~zecke/does-not-exist";, &size);
+    fail_unless (cache_data == NULL, "Failed to read it");
+    fail_unless (size == -1, "Size is wrong");
+    g_object_unref (cache);
+}
+END_TEST
+
+/*
+ * test writing and reading a file
+ */
+START_TEST (test_read_write_cache)
+{
+    GObject *cache = moko_cache_new ("moko-cache-test");
+
+    gchar *content = "Hey this is a cache test";
+    gint result = moko_cache_write_object (MOKO_CACHE(cache), 
"http://openembedded.org/~zecke/foo.withtext";, content, strlen(content), NULL);
+    g_print ("Result was %d\n", result);
+    fail_unless (result == MOKO_CACHE_WRITE_SUCCESS, "Writing the cache 
failed");
+
+    /* now try to read it */
+    gsize size;
+    gchar *content_result = moko_cache_read_object (MOKO_CACHE(cache), 
"http://openembedded.org/~zecke/foo.withtext";, &size);
+    g_print ("String: %p size: %d\n", content_result, (int)size);
+    fail_unless (content_result != NULL, "A valid string");
+    fail_unless (size == 24, "Right size");
+    fail_unless (strcmp(content_result,content) == 0, "Right text?");
+    g_free(content_result);
+    g_object_unref (cache);
+}
+END_TEST
+
+START_TEST (test_read_write_empty_cache)
+{
+    GObject *cache = moko_cache_new ("moko-cache-test");
+
+    gchar *content = "";
+    gint result = moko_cache_write_object (MOKO_CACHE(cache), 
"http://openembedded.org/~zecke/foo.empty";, content, strlen(content), NULL);
+    g_print ("Result was %d\n", result);
+    fail_unless (result == MOKO_CACHE_WRITE_SUCCESS, "Writing the cache 
failed");
+
+    /* now try to read it */
+    gsize size;
+    content = moko_cache_read_object (MOKO_CACHE(cache), 
"http://openembedded.org/~zecke/foo.empty";, &size);
+    g_print ("String: %p size: %d\n", content, (int)size);
+    fail_unless (content != NULL, "A valid string");
+    fail_unless (size == 0, "Right size");
+    g_free(content);
+    g_object_unref (cache);
+}
+END_TEST
+
+Suite*
+cache_suite (void)
+{
+    Suite *s = suite_create( "Cache" );
+    TCase *tc_core = tcase_create ("Core");
+    tcase_add_test (tc_core, test_create_cache);
+    tcase_add_test (tc_core, test_read_empty_cache);
+    tcase_add_test (tc_core, test_read_write_cache);
+    tcase_add_test (tc_core, test_read_write_empty_cache);
+    suite_add_tcase (s, tc_core);
+
+    return s;
+}
+
+int
+main (void)
+{
+    g_type_init ();
+    Suite *s = cache_suite ();
+    SRunner *sr = srunner_create (s);
+    srunner_run_all (sr, CK_NORMAL);
+    int number_failed = srunner_ntests_failed (sr);
+    srunner_free (sr);
+
+    return  (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}


Property changes on: 
trunk/src/target/OM-2007/applications/openmoko-rssreader/tests/cache_test.c
___________________________________________________________________
Name: svn:eol-style
   + native




--- End Message ---
--- Begin Message ---
Author: zecke
Date: 2007-05-18 23:59:58 +0200 (Fri, 18 May 2007)
New Revision: 2028

Modified:
   trunk/src/target/OM-2007/applications/openmoko-rssreader/ChangeLog
   
trunk/src/target/OM-2007/applications/openmoko-rssreader/src/application-data.h
   trunk/src/target/OM-2007/applications/openmoko-rssreader/src/callbacks.c
   trunk/src/target/OM-2007/applications/openmoko-rssreader/src/callbacks.h
   trunk/src/target/OM-2007/applications/openmoko-rssreader/src/main.c
Log:
2007-05-18  Holger Freyther  <[EMAIL PROTECTED]>

        Start caching data

        * src/application-data.h: Hold a MokoCache object
        * src/callbacks.c: Move the filling of the GtkListStore into a method
        to be used by the method loading from a cache. 
        (add_mrss_item): The refactored method
        (feed_update_thread): Move the code to add_mrss_item and cache the
        data.
        (load_data_from_cache): Empty stub
        * src/callbacks.h:
        * src/main.c:
        (main): Create the MokoCache


Modified: trunk/src/target/OM-2007/applications/openmoko-rssreader/ChangeLog
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-rssreader/ChangeLog  
2007-05-18 21:32:25 UTC (rev 2027)
+++ trunk/src/target/OM-2007/applications/openmoko-rssreader/ChangeLog  
2007-05-18 21:59:58 UTC (rev 2028)
@@ -1,5 +1,20 @@
 2007-05-18  Holger Freyther  <[EMAIL PROTECTED]>
 
+        Start caching data
+
+        * src/application-data.h: Hold a MokoCache object
+        * src/callbacks.c: Move the filling of the GtkListStore into a method
+        to be used by the method loading from a cache. 
+        (add_mrss_item): The refactored method
+        (feed_update_thread): Move the code to add_mrss_item and cache the
+        data.
+        (load_data_from_cache): Empty stub
+        * src/callbacks.h:
+        * src/main.c:
+        (main): Create the MokoCache
+
+2007-05-18  Holger Freyther  <[EMAIL PROTECTED]>
+
         Test the cache implementation
 
         * src/moko_cache.c:

Modified: 
trunk/src/target/OM-2007/applications/openmoko-rssreader/src/application-data.h
===================================================================
--- 
trunk/src/target/OM-2007/applications/openmoko-rssreader/src/application-data.h 
    2007-05-18 21:32:25 UTC (rev 2027)
+++ 
trunk/src/target/OM-2007/applications/openmoko-rssreader/src/application-data.h 
    2007-05-18 21:59:58 UTC (rev 2028)
@@ -33,10 +33,13 @@
 #include <libmokoui/moko-tree-view.h>
 #include <libmokoui/moko-tool-box.h>
 
+#include "moko_cache.h"
+
 #include <gtk/gtk.h>
 
 struct RSSReaderData {
     MokoApplication   *app;
+    MokoCache         *cache;
     GtkMenu           *menu;
     GtkMenu           *filter;
     MokoPanedWindow   *window;

Modified: 
trunk/src/target/OM-2007/applications/openmoko-rssreader/src/callbacks.c
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-rssreader/src/callbacks.c    
2007-05-18 21:32:25 UTC (rev 2027)
+++ trunk/src/target/OM-2007/applications/openmoko-rssreader/src/callbacks.c    
2007-05-18 21:59:58 UTC (rev 2028)
@@ -29,12 +29,14 @@
 
 #include "callbacks.h"
 #include "rfcdate.h"
+#include "moko_cache.h"
 
 #include <libmokoui/moko-tool-box.h>
 #include <gdk/gdkkeysyms.h>
 
 #include <mrss.h>
 #include <string.h>
+#include <stdlib.h>
 
 struct FeedEntry {
     gchar *category;
@@ -93,6 +95,70 @@
 void cb_subscribe_button_clicked( GtkButton *btn, struct RSSReaderData *data ) 
{}
 
 
+static
+void add_mrss_item ( struct RSSReaderData *data, const mrss_t *rss_data, const 
gchar *url, const gchar *category)
+{
+    GtkTreeIter iter;
+    mrss_item_t *item = rss_data->item;
+
+    while ( item ) {
+        gint content_type = RSS_READER_TEXT_TYPE_NONE;
+        gchar *description = item->description;
+
+        /*
+         * let us try to find the 'content' tag
+         * and then extract the type
+         */
+        if ( !description && rss_data->version == MRSS_VERSION_ATOM_1_0 && 
item->other_tags ) {
+            for ( mrss_tag_t *tag = item->other_tags; tag; tag = tag->next ) {
+                if ( strcmp( tag->name, "content" ) == 0 ) {
+                    description = tag->value;
+
+                    for ( mrss_attribute_t *attribute = tag->attributes; 
attribute; attribute = attribute->next ) {
+                        /*
+                         * Detect the type of the content. Currently we know 
about text/plain and html
+                         */
+                        if ( strcmp( attribute->name, "type" ) == 0 ) {
+                            if ( strcmp( attribute->value, "plain" ) == 0 ) {
+                                content_type = RSS_READER_TEXT_TYPE_PLAIN;
+                            } else if ( strcmp( attribute->name, "html" ) == 0 
) {
+                                content_type = RSS_READER_TEXT_TYPE_HTML;
+                            } else {
+                                content_type = RSS_READER_TEXT_TYPE_UNKNOWN;
+                            }
+                        }
+                    }
+
+                    /* we are done */
+                    break;
+                }
+            }
+        }
+
+        /*
+         * update the model here. The order in gtk_list_store_set must match
+         * with the order in application-data.h
+         */
+        RSSRFCDate *date = RSS_RFC_DATE(rss_rfc_date_new ());
+        rss_rfc_date_set (date, item->pubDate);
+        gdk_threads_enter();
+        gtk_list_store_append( data->feed_data, &iter );
+        gtk_list_store_set   ( data->feed_data, &iter,
+                RSS_READER_COLUMN_AUTHOR, g_strdup( item->author  ),
+                RSS_READER_COLUMN_SUBJECT,g_strdup( item->title   ),
+                RSS_READER_COLUMN_DATE,   date,
+                RSS_READER_COLUMN_LINK,   g_strdup( item->link    ),
+                RSS_READER_COLUMN_TEXT,   g_strdup( description   ),
+                RSS_READER_COLUMN_TEXT_TYPE, content_type          ,
+                RSS_READER_COLUMN_CATEGORY, g_strdup( category ),
+                RSS_READER_COLUMN_SOURCE,  g_strdup( url ),
+                -1 );
+        gdk_threads_leave();
+        item = item->next;
+    }
+
+}
+
 /*
  * asynchronous update thread!
  * This breaks with ATK+. See 
http://wiki.ekiga.org/index.php/Bug::ATK::Threads and bugs
@@ -115,75 +181,32 @@
  * Refilter the model...
  */
 static void feed_update_thread( struct RSSReaderData *data ) {
-    GtkTreeIter iter;
-
     for ( int i = 0; i < NUMBER_OF_FEEDS; ++i ) {
         mrss_t *rss_data;
-        int ret = mrss_parse_url( s_feeds[i].url, &rss_data );
+        gchar *url = s_feeds[i].url;
+        int ret = mrss_parse_url( url, &rss_data );
         if ( ret ) {
             /* TODO use the footer to report error? */
             g_debug( "parse_url failed.." );
             continue;
         }
 
-        mrss_item_t *item = rss_data->item;
-        while ( item ) {
-            gint content_type = RSS_READER_TEXT_TYPE_NONE;
-            gchar *description = item->description;
+        /*
+         * create the new item(s)
+         */
+        add_mrss_item (data, rss_data, url, s_feeds[i].category);
 
-            /*
-             * let us try to find the 'content' tag
-             * and then extract the type
-             */
-            if ( !description && rss_data->version == MRSS_VERSION_ATOM_1_0 && 
item->other_tags ) {
-                for ( mrss_tag_t *tag = item->other_tags; tag; tag = tag->next 
) {
-                    if ( strcmp( tag->name, "content" ) == 0 ) {
-                        description = tag->value;
-
-                        for ( mrss_attribute_t *attribute = tag->attributes; 
attribute; attribute = attribute->next ) {
-                            /*
-                             * Detect the type of the content. Currently we 
know about text/plain and html
-                             */
-                            if ( strcmp( attribute->name, "type" ) == 0 ) {
-                                if ( strcmp( attribute->value, "plain" ) == 0 
) {
-                                    content_type = RSS_READER_TEXT_TYPE_PLAIN;
-                                } else if ( strcmp( attribute->name, "html" ) 
== 0 ) {
-                                    content_type = RSS_READER_TEXT_TYPE_HTML;
-                                } else {
-                                    content_type = 
RSS_READER_TEXT_TYPE_UNKNOWN;
-                                }
-                            }
-                        }
-
-                        /* we are done */
-                        break;
-                    }
-                }
-            }
-
-            /*
-             * update the model here. The order in gtk_list_store_set must 
match
-             * with the order in application-data.h
-             */
-            RSSRFCDate *date = RSS_RFC_DATE(rss_rfc_date_new ());
-            rss_rfc_date_set (date, item->pubDate);
-            gdk_threads_enter();
-            gtk_list_store_append( data->feed_data, &iter );
-            gtk_list_store_set   ( data->feed_data, &iter,
-                                   RSS_READER_COLUMN_AUTHOR, g_strdup( 
item->author  ),
-                                   RSS_READER_COLUMN_SUBJECT,g_strdup( 
item->title   ),
-                                   RSS_READER_COLUMN_DATE,   date,
-                                   RSS_READER_COLUMN_LINK,   g_strdup( 
item->link    ),
-                                   RSS_READER_COLUMN_TEXT,   g_strdup( 
description   ),
-                                   RSS_READER_COLUMN_TEXT_TYPE, content_type   
       ,
-                                   RSS_READER_COLUMN_CATEGORY, g_strdup( 
s_feeds[i].category ),
-                                   RSS_READER_COLUMN_SOURCE,  g_strdup( 
s_feeds[i].url ),
-                                   -1 );
-            gdk_threads_leave();
-            item = item->next;
+        /*
+         * now cache the feed, a bit inefficient as we do not write to a file 
directly
+         */
+        char *buffer = NULL;
+        mrss_write_buffer (rss_data, &buffer);
+        if (buffer) {
+            moko_cache_write_object (data->cache, url, buffer, -1, NULL);
         }
 
-        mrss_free( data );
+        free (buffer);
+        mrss_free( rss_data );
     }
 
     gdk_threads_enter();
@@ -191,6 +214,13 @@
     gdk_threads_leave();
 }
 
+/**
+ * read the feeds from disk
+ */
+void load_data_from_cache (struct RSSReaderData *data)
+{
+}
+
 /*
  * Start the update-job in a separate thread
  */

Modified: 
trunk/src/target/OM-2007/applications/openmoko-rssreader/src/callbacks.h
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-rssreader/src/callbacks.h    
2007-05-18 21:32:25 UTC (rev 2027)
+++ trunk/src/target/OM-2007/applications/openmoko-rssreader/src/callbacks.h    
2007-05-18 21:59:58 UTC (rev 2028)
@@ -38,6 +38,7 @@
 /*
  * toolbox callbacks
  */
+void load_data_from_cache (struct RSSReaderData *data);
 void cb_subscribe_button_clicked  ( GtkButton *btn, struct RSSReaderData *d);
 void refresh_categories( struct RSSReaderData* );
 void refresh_feeds( struct RSSReaderData *data );

Modified: trunk/src/target/OM-2007/applications/openmoko-rssreader/src/main.c
===================================================================
--- trunk/src/target/OM-2007/applications/openmoko-rssreader/src/main.c 
2007-05-18 21:32:25 UTC (rev 2027)
+++ trunk/src/target/OM-2007/applications/openmoko-rssreader/src/main.c 
2007-05-18 21:59:58 UTC (rev 2028)
@@ -292,6 +292,7 @@
 
     data->app = MOKO_APPLICATION( moko_application_get_instance() );
     g_set_application_name( _("FeedReader") );
+    data->cache = MOKO_CACHE(moko_cache_new ("rss-reader"));
 
     setup_ui( data );
 




--- End Message ---
_______________________________________________
commitlog mailing list
[email protected]
http://lists.openmoko.org/mailman/listinfo/commitlog

Reply via email to