[Wepg-devel] common PalmAppInfo.h,NONE,1.1 PalmDB.C,NONE,1.1 PalmDB.h,NONE,1.1 RecIDList.C,NONE,1.1
Brought to you by:
leonvs
|
From: Leon v. S. <le...@us...> - 2004-08-03 17:15:20
|
Update of /cvsroot/wepg/common In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30678 Added Files: PalmAppInfo.h PalmDB.C PalmDB.h RecIDList.C RecIDList.h TimeThreshold.C TimeThreshold.h wepgstruct.h Log Message: ok --- NEW FILE: TimeThreshold.h --- /* Copyright (C) 2004 Leon van Stuivenberg <l.v...@ch...> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef __TIMETHRESHOLD_H #define __TIMETHRESHOLD_H #include "HostUser.h" class TimeThreshold { public: TimeThreshold( HostUser& hostuser ); const char* getPast() const { return m_pastStr; } const char* getFuture() const { return m_futureStr; } protected: char m_pastStr[32]; char m_futureStr[32]; private: void printTime( struct tm* t, char* dst ); }; #endif --- NEW FILE: PalmAppInfo.h --- #ifndef __PalmAppInfo_H #define __PalmAppInfo_H #include <mysql.h> #include "wepgstruct.h" #include "HostUser.h" class PalmAppInfo { public: PalmAppInfo(); int init( int psock, int db_handle ); int load( MYSQL *hostdb, HostUser& hostuser ); const char* getUserId() const; unsigned long getTimeZone() const; void setTimeZone( unsigned long tz ); const WepgAppInfoData* getPacked() const { return &m_storage; } int getPackedSize() const { return sizeof( m_storage ); } protected: WepgAppInfoData m_storage; private: }; #endif --- NEW FILE: RecIDList.C --- /* Copyright (C) 2004 Leon van Stuivenberg <l.v...@ch...> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "RecIDList.h" #include "wepgutil.h" RecIDList::RecIDList() { m_length = 0; m_ids = NULL; } RecIDList::~RecIDList() { if ( m_ids != NULL ) delete[] m_ids; } long RecIDList::load( int pilot_socket, PalmDB& palmdb ) { long retval; int numrecs = 0; retval = dlp_ReadOpenDBInfo( pilot_socket, palmdb.getHandle(), &numrecs ); if ( retval < 0 ) { errprintf( "ReadOpenDBInfo failed, %li\n", retval ); return retval; } m_length = numrecs; if ( m_length == 0 ) return 0; if ( m_ids != NULL ) delete[] m_ids; m_ids = new recordid_t[ m_length ]; if ( m_ids == NULL ) { errprintf( "out of mem\n" ); return 1; } int total = 0; while (total < m_length) { int count = 0; retval = dlp_ReadRecordIDList( pilot_socket, palmdb.getHandle(), 0, // sort total, // start m_length - total, //max m_ids + total, &count ); if ( retval < 0 ) { errprintf( "ReadRecordIDList failed, %li\n", retval ); return retval; } total += count; if (count == 0) { errprintf( "ReadRecordIDList, got %i out of %i\n", count, m_length); return 1; } } return 0; } recordid_t RecIDList::getId( int index ) const { if ( (index < 0) || (index >= m_length) ) return 0; return m_ids[ index ]; } bool RecIDList::contains( recordid_t id ) const { for ( int i=0; i<m_length; i++ ) if ( id == getId( i ) ) return true; return false; } --- NEW FILE: RecIDList.h --- /* Copyright (C) 2004 Leon van Stuivenberg <l.v...@ch...> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef __RECIDLIST_H #define __RECIDLIST_H #include "wepginc.h" #include "PalmDB.h" class RecIDList { public: RecIDList(); ~RecIDList(); long load( int pilot_socket, PalmDB& palmdb ); int getLength() const { return m_length; } recordid_t getId( int index ) const; bool contains( recordid_t id ) const; protected: int m_length; recordid_t* m_ids; }; #endif --- NEW FILE: TimeThreshold.C --- /* Copyright (C) 2004 Leon van Stuivenberg <l.v...@ch...> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "TimeThreshold.h" #include "wepgutil.h" #include <time.h> #include <asm/types.h> #include <stdlib.h> #include <stdio.h> TimeThreshold::TimeThreshold( HostUser& hostuser ) { int enddayGMT_hour = hostuser.getDayEndHourGMT(); int enddayGMT_min = hostuser.getDayEndMinuteGMT(); time_t nowtime; struct tm nowgmt; struct tm thresholdgmt; //win32 _tzset(); time( &nowtime ); nowgmt = *gmtime( &nowtime ); thresholdgmt = nowgmt; thresholdgmt.tm_hour = enddayGMT_hour; thresholdgmt.tm_min = enddayGMT_min; thresholdgmt.tm_sec = 0; time_t thresholdgmt_time = mktime( &thresholdgmt ); if ( difftime( thresholdgmt_time, nowtime ) >= 0.0 ) { thresholdgmt_time -= 60*60*24; // go back a day thresholdgmt = *gmtime( &thresholdgmt_time ); } printTime( &thresholdgmt, m_pastStr ); thresholdgmt_time += (60*60*24) * hostuser.getLoadAhead(); thresholdgmt = *gmtime( &thresholdgmt_time ); printTime( &thresholdgmt, m_futureStr ); } void TimeThreshold::printTime( struct tm* t, char* dst ) { sprintf( dst, "%04i-%02i-%02i %02i:%02i:%02i", t->tm_year + 1900, t->tm_mon+1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec ); } --- NEW FILE: PalmDB.C --- /* Copyright (C) 2004 Leon van Stuivenberg <l.v...@ch...> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "PalmDB.h" #include "wepginc.h" #include "wepgutil.h" PalmDB::PalmDB( int pilot_socket ) { m_sock = pilot_socket; m_open = false; } PalmDB::~PalmDB() { close(); } int PalmDB::open() { int retval; if ( m_open ) return 1; retval = dlp_OpenDB( m_sock, 0, dlpOpenSecret | dlpOpenExclusive | dlpOpenWrite | dlpOpenRead, DB_NAME, &m_handle); if ( retval < 0 ) { errprintf( "OpenDB failed, %i\n", retval ); return retval; } m_open = true; return 0; } int PalmDB::close() { if ( !m_open ) return 1; dlp_CloseDB( m_sock, m_handle); m_open = false; return 0; } --- NEW FILE: PalmDB.h --- #ifndef __PalmDB_H #define __PalmDB_H #define DB_NAME "WepgDB" class PalmDB { public: PalmDB( int pilot_socket ); ~PalmDB(); int open(); int close(); int getHandle() const { return m_handle; } protected: int m_sock; bool m_open; int m_handle; private: }; #endif --- NEW FILE: wepgstruct.h --- #ifndef __wepgstruct_H #define __wepgstruct_H extern "C" { #pragma pack(1) typedef struct { unsigned long minute :6; // 0..59 (lsb's in dword) unsigned long hour :5; // 0..23 unsigned long day :5; // 1..31 unsigned long month :4; // 1..12 unsigned long year :12; // 0..1999..4095 (msb's in dword) } WepgDBTimeStamp; typedef struct { unsigned long have_title :1; unsigned long have_info :1; unsigned long watched :1; unsigned long seen_it :1; unsigned long must_see :1; unsigned long alarm :1; unsigned long sys_seen_it :1; unsigned long res1 :1; unsigned long category :4; unsigned long system_rating :3; unsigned long res2 :1; unsigned long user_rating :3; unsigned long res3 :1; unsigned long unread :1; unsigned long record :1; unsigned long sysrecord :1; unsigned long recorded :1; //... unsigned long reserved :8; } WepgDBRecordFlags; // see UserBroadcast.java #define FLAG_WATCHED 0x01 #define FLAG_SEENIT 0x02 #define FLAG_MUSTSEE 0x04 #define FLAG_ALARM 0x08 #define FLAG_SYSSEENIT 0x10 #define FLAG_UNREAD 0x20 #define FLAG_RECORD 0x40 #define FLAG_SYSRECORD 0x80 #define FLAG_RECORDED 0x100 #define STATUS_NONE 0x00 #define STATUS_UPDATE 0x02 typedef struct { WepgDBRecordFlags flags; WepgDBTimeStamp start_time; WepgDBTimeStamp end_time; unsigned char station_id; //title (asciiz) //info (asciiz) } WepgDBPackedRec; #define APPNUMSTATIONS 64 #define APPNUMCATEGORIES 16 #define APPLABELLENGTH 16 #define UIDLEN 16 typedef struct { char appinfo[ 2+16*16+16+1 +3 ]; // standard palm appinfo char user_id[ UIDLEN ]; char station_labels[APPNUMSTATIONS][ APPLABELLENGTH ]; char station_enabled[APPNUMSTATIONS]; unsigned char station_listpos[APPNUMSTATIONS]; char category_labels[APPNUMCATEGORIES][ APPLABELLENGTH ]; char category_dirty[APPNUMCATEGORIES]; unsigned long timezone; char db_credit; char sort_order; char view_mode; unsigned char view_start_hour; unsigned char view_start_min; unsigned char day_end_hour; unsigned char day_end_min; unsigned char load_ahead; // unsigned char _pad[1]; } WepgAppInfoData; #pragma pack() }//C #endif |