From: Kristen Carlson Accardi <kristen@linux.intel.com>
To: ofono@ofono.org
Subject: [PATCH 1/4] simfs: cache images
Date: Mon, 04 Oct 2010 15:33:19 -0700 [thread overview]
Message-ID: <1286231602-18692-2-git-send-email-kristen@linux.intel.com> (raw)
In-Reply-To: <1286231602-18692-1-git-send-email-kristen@linux.intel.com>
[-- Attachment #1: Type: text/plain, Size: 2471 bytes --]
---
src/simfs.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/simfs.h | 4 +++
2 files changed, 66 insertions(+), 0 deletions(-)
diff --git a/src/simfs.c b/src/simfs.c
index b5b12b4..5fbee8b 100644
--- a/src/simfs.c
+++ b/src/simfs.c
@@ -47,6 +47,7 @@
#define SIM_CACHE_PATH SIM_CACHE_BASEPATH "/%04x"
#define SIM_CACHE_HEADER_SIZE 38
#define SIM_FILE_INFO_SIZE 6
+#define SIM_IMAGE_CACHE_PATH STORAGEDIR "/%s-%i/images/%d.xpm"
#define SIM_FS_VERSION 1
@@ -722,6 +723,67 @@ int sim_fs_write(struct sim_fs *fs, int id, ofono_sim_file_write_cb_t cb,
return 0;
}
+void sim_fs_cache_image(struct sim_fs *fs, const char *image, int id)
+{
+ const char *imsi;
+ enum ofono_sim_phase phase;
+
+ if (fs == NULL || image == NULL)
+ return;
+
+ imsi = ofono_sim_get_imsi(fs->sim);
+ phase = ofono_sim_get_phase(fs->sim);
+
+ if (imsi)
+ write_file((const unsigned char *) image, strlen(image),
+ SIM_CACHE_MODE, SIM_IMAGE_CACHE_PATH, imsi,
+ phase, id);
+}
+
+char *sim_fs_get_cached_image(struct sim_fs *fs, int id)
+{
+ const char *imsi;
+ enum ofono_sim_phase phase;
+ unsigned short image_length;
+ int fd;
+ char *buffer;
+ char *path;
+ int len;
+ struct stat st_buf;
+
+ if (fs == NULL)
+ return NULL;
+
+ imsi = ofono_sim_get_imsi(fs->sim);
+ phase = ofono_sim_get_phase(fs->sim);
+
+ path = g_strdup_printf(SIM_IMAGE_CACHE_PATH, imsi, phase, id);
+
+ TFR(stat(path, &st_buf));
+
+ fd = TFR(open(path, O_RDONLY));
+
+ g_free(path);
+
+ if (fd < 0)
+ return NULL;
+
+ image_length = st_buf.st_size;
+
+ buffer = g_try_malloc0(image_length + 1);
+
+ len = TFR(read(fd, buffer, image_length));
+
+ TFR(close(fd));
+
+ if (len != image_length) {
+ g_free(buffer);
+ return NULL;
+ }
+
+ return buffer;
+}
+
static void remove_cachefile(const char *imsi, enum ofono_sim_phase phase,
const struct dirent *file)
{
diff --git a/src/simfs.h b/src/simfs.h
index 6d5dded..c0b4c51 100644
--- a/src/simfs.h
+++ b/src/simfs.h
@@ -35,4 +35,8 @@ int sim_fs_write(struct sim_fs *fs, int id, ofono_sim_file_write_cb_t cb,
enum ofono_sim_file_structure structure, int record,
const unsigned char *data, int length, void *userdata);
+char *sim_fs_get_cached_image(struct sim_fs *fs, int id);
+
+void sim_fs_cache_image(struct sim_fs *fs, const char *image, int id);
+
void sim_fs_free(struct sim_fs *fs);
--
1.7.2.1
next prev parent reply other threads:[~2010-10-04 22:33 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-04 22:33 [PATCH 0/4] Icon patches (rebased) Kristen Carlson Accardi
2010-10-04 22:33 ` Kristen Carlson Accardi [this message]
2010-10-12 1:16 ` [PATCH 1/4] simfs: cache images Denis Kenzior
2010-10-04 22:33 ` [PATCH 2/4] sim: implement GetIcon Kristen Carlson Accardi
2010-10-13 13:44 ` Denis Kenzior
2010-10-04 22:33 ` [PATCH 3/4] simfs: fix incorrect math when calculating length to copy Kristen Carlson Accardi
2010-10-13 13:44 ` Denis Kenzior
2010-10-14 18:18 ` [PATCH] simfs: fix incorrect math again Kristen Carlson Accardi
2010-11-02 14:41 ` Kristen Carlson Accardi
2010-11-02 14:57 ` Denis Kenzior
2010-11-29 19:13 ` [PATCH] simfs: make sim_fs_read_block work for > 256 byte files Kristen Carlson Accardi
2010-10-04 22:33 ` [PATCH 4/4] simutil: add file type for EFimg Kristen Carlson Accardi
2010-10-12 3:16 ` Denis Kenzior
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1286231602-18692-2-git-send-email-kristen@linux.intel.com \
--to=kristen@linux.intel.com \
--cc=ofono@ofono.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox