[pkg-fso-commits] [SCM] libframeworkd-phonegui branch, upstream, updated. 640da47bfcff755388d0fb8f443eb34e0dea3c72

Didier 'Ptitjes ptitjes at free.fr
Sat Dec 27 20:50:04 UTC 2008


The following commit has been merged in the upstream branch:
commit 016071921b76f5ee4a8b3f509c4c87646840ecf0
Author: Didier 'Ptitjes <ptitjes at free.fr>
Date:   Sat Dec 6 11:41:44 2008 +0100

    Added phone log on sqlite
    Signed-off-by: Didier 'Ptitjes <ptitjes at free.fr>

diff --git a/ophonekitd/src/ophonekitd-phonelog.c b/ophonekitd/src/ophonekitd-phonelog.c
new file mode 100644
index 0000000..02e4fc9
--- /dev/null
+++ b/ophonekitd/src/ophonekitd-phonelog.c
@@ -0,0 +1,154 @@
+/*
+ *  Copyright (C) 2008
+ *      Authors (alphabetical) :
+ *              Didier "Ptitjes" <ptitjes at free.fr>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Public License as published by
+ *  the Free Software Foundation; version 2 of the license.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU Lesser Public License for more details.
+ */
+
+#include "ophonekitd-phonelog.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include <sqlite3.h>
+
+#define PHONELOG_DB_LOCATION "/var/log/phonelog.db"
+#define PHONELOG_CREATE_CALL_IDS_TABLE \
+	"CREATE TABLE call_ids (id INTEGER PRIMARY KEY, number TEXT)"
+#define PHONELOG_CREATE_CALL_EVENTS_TABLE \
+	"CREATE TABLE call_events (id INTEGER, status INT, eventTime DATE, FOREIGN KEY (id) REFERENCES call_ids(id))"
+#define PHONELOG_CREATE_CALL_EVENTS_TRIGGER \
+	"CREATE TRIGGER insert_call_events_eventTime AFTER  INSERT ON call_events\nBEGIN\nUPDATE call_events SET eventTime = DATETIME('NOW')  WHERE rowid = new.rowid;\nEND"
+
+sqlite3 *db;
+
+void phonelog_init_database() {
+	int rc;
+	char *err = 0;
+	struct stat info;
+	int dbIsNew;
+
+	/* Test whether the database file exists */
+	dbIsNew = stat(PHONELOG_DB_LOCATION, &info) != 0;
+
+	if (dbIsNew) {
+		g_debug("phonelog - creating database tables and triggers");
+	}
+
+	/* Open the database */
+	rc = sqlite3_open(PHONELOG_DB_LOCATION, &db);
+	if (rc) {
+		g_debug("phonelog - can't open database: %s\n", sqlite3_errmsg(db));
+		sqlite3_close(db);
+		return;
+	}
+
+	/* Create the call_events table and trigger if the database is new */
+	if (dbIsNew) {
+		rc = sqlite3_exec(db, PHONELOG_CREATE_CALL_IDS_TABLE, 0, 0, &err);
+		if (rc != SQLITE_OK) {
+			g_debug("phonelog - SQL error: %s\n", err);
+			sqlite3_free(&err);
+
+			sqlite3_close(db);
+			db = 0;
+			return;
+		}
+
+		rc = sqlite3_exec(db, PHONELOG_CREATE_CALL_EVENTS_TABLE, 0, 0, &err);
+		if (rc != SQLITE_OK) {
+			g_debug("phonelog - SQL error: %s\n", err);
+			sqlite3_free(&err);
+
+			sqlite3_close(db);
+			db = 0;
+			return;
+		}
+
+		rc = sqlite3_exec(db, PHONELOG_CREATE_CALL_EVENTS_TRIGGER, 0, 0, &err);
+		if (rc != SQLITE_OK) {
+			g_debug("phonelog - SQL error: %s\n", err);
+			sqlite3_free(&err);
+
+			sqlite3_close(db);
+			db = 0;
+			return;
+		}
+	}
+}
+
+void phonelog_close_database() {
+	/* Close the database */
+	if (db) {
+		sqlite3_close(db);
+	}
+}
+
+int phonelog_add_new_call(const gchar* number) {
+	int rc;
+	char *err = 0;
+	char *stmt = 0;
+
+	if (db) {
+		g_debug("phonelog - add new call, number: %s", number);
+
+		stmt = malloc(51 + strlen(number) + 1);
+		sprintf(stmt, "INSERT INTO call_ids (id, number) values (NULL, %s)",
+				number);
+		g_debug(stmt);
+
+		rc = sqlite3_exec(db, stmt, 0, 0, &err);
+		free(stmt);
+
+		if (rc != SQLITE_OK) {
+			g_debug("phonelog - SQL error: %s\n", err);
+			sqlite3_free(&err);
+			return -1;
+		}
+
+		return sqlite3_last_insert_rowid(db);
+	}
+}
+
+void phonelog_log_call_event(const int unique_id, const int status) {
+	int rc;
+	char *err = 0;
+	char *stmt = 0;
+
+	g_debug("phonelog - logging call event, unique id: %u, status: %d",
+			unique_id, status);
+
+	if (db) {
+		stmt = malloc(48 + 100 + 1);
+		sprintf(stmt, "INSERT INTO call_events (id, status) values (%u, %u)",
+				unique_id, status);
+		g_debug(stmt);
+
+		rc = sqlite3_exec(db, stmt, 0, 0, &err);
+		free(stmt);
+
+		if (rc != SQLITE_OK) {
+			g_debug("phonelog - SQL error: %s\n", err);
+			sqlite3_free(&err);
+		}
+	}
+}
+
+/*static int callback(void *NotUsed, int argc, char **argv, char **azColName) {
+ NotUsed = 0;
+ int i;
+ for (i = 0; i < argc; i++) {
+ printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
+ }
+ printf("\n");
+ return 0;
+ }*/
diff --git a/openmoko-messages3/src/messages-main.h b/ophonekitd/src/ophonekitd-phonelog.h
similarity index 65%
copy from openmoko-messages3/src/messages-main.h
copy to ophonekitd/src/ophonekitd-phonelog.h
index b33ecb0..47e3b0d 100644
--- a/openmoko-messages3/src/messages-main.h
+++ b/ophonekitd/src/ophonekitd-phonelog.h
@@ -1,7 +1,7 @@
 /*
  *  Copyright (C) 2008
  *      Authors (alphabetical) :
- *              quickdev
+ *              Didier "Ptitjes" <ptitjes at free.fr>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU Public License as published by
@@ -13,14 +13,15 @@
  *  GNU Lesser Public License for more details.
  */
 
-#ifndef _MESSAGES_MAIN_H
-#define _MESSAGES_MAIN_H
+#ifndef _OPHONEKITD_PHONELOG_H
+#define _OPHONEKITD_PHONELOG_H
 
 #include <dbus/dbus-glib.h>
 
-int main(int argc, char **argv);
-void connect_to_frameworkd();
-void exit_callback();
-gboolean start();
+void phonelog_init_database();
+void phonelog_close_database();
+
+int phonelog_add_new_call(const gchar* number);
+void phonelog_log_call_event(const int unique_id, const int status);
 
 #endif

-- 
libframeworkd-phonegui



More information about the pkg-fso-commits mailing list