palm-client: one DbOpen for the three stores (in vmcode4: frees 420 bytes of vmcode2; the channel cache is now backed up too); notes on why session.c stays in segment 1 and on AppLoadPrefs loading every module's prefs

This commit is contained in:
rich committed 2026-11-04 07:36:27 -05:00
1 parent 14c18b95ee
commit aa3a5da9fe
8 files changed
+54 -61

No files matched your search

+1 -1
View File
@@ -11,7 +11,7 @@ APP = visormesh
NAME = VisorMesh
CREATOR = VMsh
SRCS = src/main.c src/app.c src/home_form.c src/convo_form.c src/node_form.c src/channel_form.c src/convos.c src/protocol.c src/sha256.c src/transport_srm.c src/transport_sb.c src/sb_spi.c src/session.c src/settings.c src/presets.c src/contacts.c src/contacts_form.c src/contact_form.c src/heard.c src/remote_fmt.c src/remote.c src/remote_form.c src/messages.c src/channels.c src/preview_form.c src/ui/draw.c src/ui/text.c src/ui/rowlist.c src/ui/fontmetrics.c src/ports.c src/sounds.c src/mutes.c src/scopes.c src/scope_proto.c src/map_geo.c src/map_form.c src/ui/emoji.c src/bgcheck.c src/pins.c src/shots.c
SRCS = src/main.c src/app.c src/home_form.c src/convo_form.c src/node_form.c src/channel_form.c src/convos.c src/protocol.c src/sha256.c src/transport_srm.c src/transport_sb.c src/sb_spi.c src/session.c src/settings.c src/presets.c src/contacts.c src/contacts_form.c src/contact_form.c src/heard.c src/remote_fmt.c src/remote.c src/remote_form.c src/messages.c src/channels.c src/preview_form.c src/ui/draw.c src/ui/text.c src/ui/rowlist.c src/ui/fontmetrics.c src/ports.c src/sounds.c src/mutes.c src/scopes.c src/scope_proto.c src/map_geo.c src/map_form.c src/ui/emoji.c src/bgcheck.c src/pins.c src/shots.c src/db.c
OBJS = $(SRCS:src/%.c=build/%.o)
CC = m68k-palmos-gcc
+3 -1
View File
@@ -19,7 +19,9 @@ void AppOpenConversation(const VmConv *conv);
/*
* Loads/saves the link choice (USB or serial, so the app reconnects the same way)
* and the UTC offset (the Visor's clock has no time zone).
* and the UTC offset (the Visor's clock has no time zone). AppLoadPrefs also
* loads every module's own prefs (sounds, mutes, scopes, pins): the
* closed-app check (BgCheckRun) relies on it, so add new ones there.
*/
void AppLoadPrefs(void);
void AppSavePrefs(void);
+2 -17
View File
@@ -1,4 +1,5 @@
#include <PalmOS.h>
#include "db.h"
#include "protocol.h"
#include "session.h"
#include "channels.h"
@@ -14,28 +15,12 @@ static void RefileMessages(UInt16 oldCount, UInt8 maxChannels) VM_SECT2;
static Char DB_NAME[] = "VisorMeshChannels";
static Char kEmpty[] = "";
#define DB_TYPE 'chan'
#define DB_CREATOR 'VMsh'
static DmOpenRef gDb = 0;
Err ChannelsOpen(void)
{
LocalID id;
Err err;
if (gDb)
return errNone;
id = DmFindDatabase(0, DB_NAME);
if (!id) {
err = DmCreateDatabase(0, DB_NAME, DB_CREATOR, DB_TYPE, false);
if (err != errNone)
return err;
id = DmFindDatabase(0, DB_NAME);
if (!id)
return DmGetLastErr();
}
gDb = DmOpenDatabase(0, id, dmModeReadWrite);
return gDb ? errNone : DmGetLastErr();
return gDb ? errNone : DbOpen(DB_NAME, DB_TYPE, &gDb);
}
void ChannelsClose(void)
+2 -21
View File
@@ -1,4 +1,5 @@
#include <PalmOS.h>
#include "db.h"
#include "protocol.h"
#include "session.h"
#include "contacts.h"
@@ -12,33 +13,13 @@ static Err UpsertContact(const VmContact *c, void *ctx) VM_SECT4;
/* a data array, not a literal: this module is in the second code segment (sections.h) */
static Char DB_NAME[] = "VisorMeshContacts";
#define DB_TYPE 'cont'
#define DB_CREATOR 'VMsh'
static DmOpenRef gDb = 0;
static UInt32 gLastMod = 0; /* newest lastmod of the last download in this run; 0: none yet */
Err ContactsOpen(void)
{
LocalID id;
UInt16 attrs;
Err err;
if (gDb)
return errNone;
id = DmFindDatabase(0, DB_NAME);
if (!id) {
err = DmCreateDatabase(0, DB_NAME, DB_CREATOR, DB_TYPE, false);
if (err != errNone)
return err;
id = DmFindDatabase(0, DB_NAME);
if (!id)
return DmGetLastErr();
DmDatabaseInfo(0, id, NULL, &attrs, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
attrs |= dmHdrAttrBackup;
DmSetDatabaseInfo(0, id, NULL, &attrs, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
}
gDb = DmOpenDatabase(0, id, dmModeReadWrite);
return gDb ? errNone : DmGetLastErr();
return gDb ? errNone : DbOpen(DB_NAME, DB_TYPE, &gDb);
}
void ContactsClose(void)
+25
View File
@@ -0,0 +1,25 @@
#include <PalmOS.h>
#include "app.h"
#include "db.h"
Err DbOpen(const Char *name, UInt32 type, DmOpenRef *db)
{
LocalID id = DmFindDatabase(0, name);
UInt16 attrs;
Err err;
*db = 0;
if (!id) {
err = DmCreateDatabase(0, name, VM_CREATOR, type, false);
if (err != errNone)
return err;
id = DmFindDatabase(0, name);
if (!id)
return DmGetLastErr();
DmDatabaseInfo(0, id, NULL, &attrs, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
attrs |= dmHdrAttrBackup;
DmSetDatabaseInfo(0, id, NULL, &attrs, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
}
*db = DmOpenDatabase(0, id, dmModeReadWrite);
return *db ? errNone : DmGetLastErr();
}
+14
View File
@@ -0,0 +1,14 @@
/*
* The app's record databases (messages, contacts, channels): open one,
* creating it with the backup bit (HotSync keeps a copy) the first time.
*/
#ifndef VM_DB_H
#define VM_DB_H
#include <PalmOS.h>
#include "sections.h"
/* Opens name read/write into *db (0 on error), creating it with VM_CREATOR and type if missing. */
Err DbOpen(const Char *name, UInt32 type, DmOpenRef *db) VM_SECT4;
#endif
+2 -21
View File
@@ -1,4 +1,5 @@
#include <PalmOS.h>
#include "db.h"
#include "protocol.h"
#include "ui/text.h"
#include "messages.h"
@@ -14,7 +15,6 @@ static void TagChannel(VmConv *conv) VM_SECT2;
/* a data array, not a literal: this module is in the second code segment (sections.h) */
static Char DB_NAME[] = "VisorMeshMessages";
#define DB_TYPE 'msgs'
#define DB_CREATOR 'VMsh'
#define TEXT_MAX (VM_MAX_FRAME + 1)
static DmOpenRef gDb = 0;
@@ -27,26 +27,7 @@ static UInt32 gNextAckDeadline = 1;
Err MessagesOpen(void)
{
LocalID id;
UInt16 attrs;
Err err;
if (gDb)
return errNone;
id = DmFindDatabase(0, DB_NAME);
if (!id) {
err = DmCreateDatabase(0, DB_NAME, DB_CREATOR, DB_TYPE, false);
if (err != errNone)
return err;
id = DmFindDatabase(0, DB_NAME);
if (!id)
return DmGetLastErr();
DmDatabaseInfo(0, id, NULL, &attrs, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
attrs |= dmHdrAttrBackup;
DmSetDatabaseInfo(0, id, NULL, &attrs, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
}
gDb = DmOpenDatabase(0, id, dmModeReadWrite);
return gDb ? errNone : DmGetLastErr();
return gDb ? errNone : DbOpen(DB_NAME, DB_TYPE, &gDb);
}
void MessagesClose(void)
+5
View File
@@ -1,3 +1,8 @@
/*
* In the first code segment, and it must stay there: the reply-code tables
* are static const inside functions, which read as garbage from an extra
* segment (sections.h). It's also on the closed-app check's path.
*/
#include <PalmOS.h>
#include "protocol.h"
#include "transport.h"