[909] in BarnOwl Developers

home help back first fref pref prev next nref lref last post

[D-O-H] r897 - branches/barnowl_sqlite/owl

daemon@ATHENA.MIT.EDU (nelhage@MIT.EDU)
Thu Oct 29 18:11:01 2009

Resent-From: nelhage@mit.edu
Resent-To: barnowl-dev-mtg@charon.mit.edu
To: dirty-owl-hackers@mit.edu
From: nelhage@MIT.EDU
Reply-to: dirty-owl-hackers@MIT.EDU
Date: Thu, 17 Jan 2008 20:24:58 -0500 (EST)

Author: nelhage
Date: 2008-01-17 20:24:57 -0500 (Thu, 17 Jan 2008)
New Revision: 897

Added:
   branches/barnowl_sqlite/owl/createdb.pl
Modified:
   branches/barnowl_sqlite/owl/owl.c
   branches/barnowl_sqlite/owl/perlglue.xs
   branches/barnowl_sqlite/owl/perlwrap.pm
Log:
First prototype of a SQL-backed message list. This is probably
horribly broken, and is painfully slow at the moment.


Added: branches/barnowl_sqlite/owl/createdb.pl
===================================================================
--- branches/barnowl_sqlite/owl/createdb.pl	                        (rev 0)
+++ branches/barnowl_sqlite/owl/createdb.pl	2008-01-18 01:24:57 UTC (rev 897)
@@ -0,0 +1,92 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+
+use DBI;
+use DBIx::DBSchema;
+
+=head1 DESCRIPTION
+
+Creates the database tables for BarnOwl::MessageList::SQL
+
+=cut
+
+my $messages = DBIx::DBSchema::Table->new({
+    name          => 'messages',
+    primary_key   => 'id',
+    columns       => [
+        DBIx::DBSchema::Column->new({
+            name => 'id',
+            type => 'int',
+            null => 0
+           }),
+        DBIx::DBSchema::Column->new({
+            name => 'msg_time',
+            type => 'int',
+            null => 0,
+           }),
+        DBIx::DBSchema::Column->new({
+            name   => 'protocol',
+            type   => 'varchar',
+            length => 30,
+            null   => 0,
+           }),
+        DBIx::DBSchema::Column->new({
+            name   => 'body',
+            type   => 'text',
+            null   => 0,
+           }),
+        DBIx::DBSchema::Column->new({
+            name   => 'direction',
+            type   => 'varchar',
+            length => 10,
+            null   => 0,
+           }),
+        ],
+    'index'       => DBIx::DBSchema::ColGroup::Index->new([
+        ]),
+   });
+
+my $attrs = DBIx::DBSchema::Table->new({
+    name        => 'attributes',
+    columns     => [
+        DBIx::DBSchema::Column->new({
+            name => 'message_id',
+            type => 'int',
+            null => 0
+           }),
+        DBIx::DBSchema::Column->new({
+            name   => 'key',
+            type   => 'varchar',
+            length => 30
+           }),
+        DBIx::DBSchema::Column->new({
+            name   => 'value',
+            type   => 'text',
+            null   => 0,
+           }),
+       ],
+    unique        => DBIx::DBSchema::ColGroup::Unique->new([
+        [qw(message_id key)],
+        ]),
+    'index'       => DBIx::DBSchema::ColGroup::Index->new([
+        [qw(message_id key)],
+        [qw(key)],
+        ]),
+   });
+
+my $schema = DBIx::DBSchema->new($messages, $attrs);
+
+my $dsn = shift;
+my $user = shift;
+my $pass = shift;
+
+my $dbh = DBI->connect($dsn, $user, $pass, {RaiseError => 1, AutoCommit => 0});
+my @sql = $schema->sql($dbh);
+
+for my $sql (@sql) {
+    $dbh->do($sql) or die($dbh->errstr);
+}
+
+$dbh->commit;
+$dbh->disconnect;

Modified: branches/barnowl_sqlite/owl/owl.c
===================================================================
--- branches/barnowl_sqlite/owl/owl.c	2008-01-17 19:55:22 UTC (rev 896)
+++ branches/barnowl_sqlite/owl/owl.c	2008-01-18 01:24:57 UTC (rev 897)
@@ -335,18 +335,21 @@
   tw=owl_global_get_typwin(&g);
 
   /* welcome message */
-  owl_function_debugmsg("startup: creating splash message");
-  strcpy(startupmsg, "-----------------------------------------------------------------------\n");
-  sprintf(buff,      "Welcome to barnowl version %s.  Press 'h' for on-line help.            \n", OWL_VERSION_STRING);
-  strcat(startupmsg, buff);
-  strcat(startupmsg, "                                                                       \n");
-  strcat(startupmsg, "This is a development build of barnowl. If you are using this          \n");
-  strcat(startupmsg, "build regularly, please add yourself to barnowl-users@mit.edu          \n");
-  strcat(startupmsg, "                                                                 ^ ^   \n");
-  strcat(startupmsg, "                                                                 OvO   \n");
-  strcat(startupmsg, "Please report any bugs to dirty-owl-hackers@mit.edu             (   )  \n");
-  strcat(startupmsg, "-----------------------------------------------------------------m-m---\n");
-  owl_function_adminmsg("", startupmsg);
+  if(owl_messagelist_get_size(owl_global_get_msglist(&g)) == 0) {
+    owl_function_debugmsg("startup: creating splash message");
+    strcpy(startupmsg, "-----------------------------------------------------------------------\n");
+    sprintf(buff,      "Welcome to barnowl version %s.  Press 'h' for on-line help.            \n", OWL_VERSION_STRING);
+    strcat(startupmsg, buff);
+    strcat(startupmsg, "                                                                       \n");
+    strcat(startupmsg, "This is a development build of barnowl. If you are using this          \n");
+    strcat(startupmsg, "build regularly, please add yourself to barnowl-users@mit.edu          \n");
+    strcat(startupmsg, "                                                                 ^ ^   \n");
+    strcat(startupmsg, "                                                                 OvO   \n");
+    strcat(startupmsg, "Please report any bugs to dirty-owl-hackers@mit.edu             (   )  \n");
+    strcat(startupmsg, "-----------------------------------------------------------------m-m---\n");
+    owl_function_adminmsg("", startupmsg);
+  }
+
   sepbar(NULL);
 
   /* process the startup file */

Modified: branches/barnowl_sqlite/owl/perlglue.xs
===================================================================
--- branches/barnowl_sqlite/owl/perlglue.xs	2008-01-17 19:55:22 UTC (rev 896)
+++ branches/barnowl_sqlite/owl/perlglue.xs	2008-01-18 01:24:57 UTC (rev 897)
@@ -255,6 +255,14 @@
 	}
 
 void
+debug(text)
+	char *text
+	CODE:
+	{
+		owl_function_debugmsg("%s", text);
+	}
+
+void
 _create_style(name, function, description)
      char *name
      char *function
@@ -341,3 +349,10 @@
 				      summ,
 				      desc,
 				      ival);
+
+SV*
+message_list()
+	CODE:
+		RETVAL = newSVsv(owl_global_get_msglist(&g));
+	OUTPUT:
+		RETVAL

Modified: branches/barnowl_sqlite/owl/perlwrap.pm
===================================================================
--- branches/barnowl_sqlite/owl/perlwrap.pm	2008-01-17 19:55:22 UTC (rev 896)
+++ branches/barnowl_sqlite/owl/perlwrap.pm	2008-01-18 01:24:57 UTC (rev 897)
@@ -118,6 +118,10 @@
 callback or hook called in perl code from BarnOwl, a C<die> will be
 caught and passed to C<error>.
 
+=head2 debug STRING
+
+Logs a debugging message to BarnOwl's debug log
+
 =head2 getnumcolors
 
 Returns the number of colors this BarnOwl is capable of displaying
@@ -292,6 +296,12 @@
 
 package BarnOwl::MessageList;
 
+my $__next_id = 0;
+
+sub next_id {
+    return $__next_id++;
+}
+
 sub new {
     my $ml;
     eval q{
@@ -355,20 +365,21 @@
 package BarnOwl::Message;
 use POSIX qw(ctime);
 
-my $__next_id = 0;
-
 sub new {
     my $class = shift;
     my $time = time;
     my $timestr = ctime($time);
     $timestr =~ s/\n$//;
     my %args = (
-        id        => $__next_id++,
         deleted   => 0,
         time      => $timestr,
         _time     => $time,
         direction => 'none',
         @_);
+    unless(exists($args{id})) {
+        my $msglist = BarnOwl::message_list();
+        $args{id} = $msglist->next_id;
+    }
     if(exists $args{loginout} && !exists $args{login}) {
         $args{login} = $args{loginout};
         delete $args{loginout};


home help back first fref pref prev next nref lref last post