32 #ifndef __DATABASE_ENGINE_H__
33 #define __DATABASE_ENGINE_H__
44 #include "sbIDatabaseEngine.h"
49 #include <nsAutoLock.h>
50 #include <nsAutoPtr.h>
51 #include <nsCOMArray.h>
52 #include <nsRefPtrHashtable.h>
53 #include <nsServiceManagerUtils.h>
54 #include <nsIIdleService.h>
55 #include <nsIThread.h>
56 #include <nsIThreadPool.h>
57 #include <nsThreadUtils.h>
58 #include <nsIRunnable.h>
59 #include <nsIObserver.h>
60 #include <nsStringGlue.h>
67 #define SONGBIRD_DATABASEENGINE_CONTRACTID \
68 "@songbirdnest.com/Songbird/DatabaseEngine;1"
69 #define SONGBIRD_DATABASEENGINE_CLASSNAME \
70 "Songbird Database Engine Interface"
71 #define SONGBIRD_DATABASEENGINE_CID \
76 {0x9d, 0x76, 0x59, 0x18, 0x18, 0x1, 0xe1, 0x93} \
82 void SQLiteUpdateHook(
void *pData,
int nOp,
const char *pArgA,
const char *pArgB, sqlite_int64 nRowID);
98 NS_DECL_SBIDATABASEENGINE
106 const NATIVE_CHAR_TYPE *aStr1,
107 const NATIVE_CHAR_TYPE *aStr2);
118 nsresult
OpenDB(
const nsAString &dbGUID,
120 sqlite3 ** ppHandle);
122 nsresult
CloseDB(sqlite3 *pHandle);
136 typedef std::list<CDatabaseQuery *> querylist_t;
139 void ReportError(sqlite3*, sqlite3_stmt*);
141 nsresult InitMemoryConstraints();
143 nsresult GetDBPrefs(
const nsAString &dbGUID,
147 nsresult CreateDBStorePath();
148 nsresult GetDBStorePath(
const nsAString &dbGUID,
CDatabaseQuery *pQuery, nsAString &strPath);
150 nsresult GetCurrentCollationLocale(nsCString &aCollationLocale);
152 const NATIVE_CHAR_TYPE *aStr1,
153 PRInt32 *number1Length,
154 const NATIVE_CHAR_TYPE *aStr2,
155 PRInt32 *number2Length);
157 const NATIVE_CHAR_TYPE *aStr1,
158 const NATIVE_CHAR_TYPE *aStr2);
160 nsresult MarkDatabaseForPotentialDeletion(
const nsAString &aDatabaseGUID,
162 nsresult PromptToDeleteDatabases();
163 nsresult DeleteMarkedDatabases();
165 nsresult RunAnalyze();
168 typedef std::map<sqlite3 *, collationBuffers *> collationMap_t;
169 collationMap_t m_CollationBuffersMap;
171 PRLock * m_pDBStorePathLock;
172 nsString m_DBStorePath;
175 nsRefPtrHashtableMT<nsStringHashKey, QueryProcessorQueue> m_QueuePool;
178 static NS_HIDDEN_(PLDHashOperator)
179 EnumerateIntoArrayStringKey(const nsAString& aKey,
183 PRMonitor* m_pThreadMonitor;
184 PRMonitor* m_CollationBuffersMapMonitor;
186 PRBool m_AttemptShutdownOnDestruction;
189 PRBool m_MemoryConstraintsSet;
191 PRBool m_PromptForDelete;
192 PRBool m_DeleteDatabases;
194 typedef std::map<nsString, nsRefPtr<
CDatabaseQuery> > deleteDatabaseMap_t;
195 deleteDatabaseMap_t m_DatabasesToDelete;
197 nsCOMPtr<nsITimer> m_PromptForDeleteTimer;
199 nsCOMPtr<nsIThreadPool> m_pThreadPool;
202 PRPackedBool m_AddedIdleObserver;
208 void* m_pScratchSpace;
210 nsCString mCollationLocale;
212 CollatorRef m_Collator;
252 const nsAString &aGUID,
254 NS_ENSURE_ARG_POINTER(pEngine);
255 NS_ENSURE_ARG_POINTER(pHandle);
260 m_pQueueMonitor = nsAutoMonitor::NewMonitor(
"QueryProcessorQueue.m_pQueueMonitor");
276 NS_ENSURE_TRUE(
m_pEngine, NS_ERROR_NOT_INITIALIZED);
285 PRBool bPushToFront = PR_FALSE) {
286 NS_ENSURE_ARG_POINTER(pQuery);
293 p =
m_Queue.InsertElementAt(0, pQuery);
295 p =
m_Queue.AppendElement(pQuery);
298 NS_ENSURE_TRUE(p, NS_ERROR_OUT_OF_MEMORY);
304 NS_ENSURE_ARG_POINTER(ppQuery);
315 return NS_ERROR_NOT_AVAILABLE;
330 queryqueue_t::size_type current = 0;
331 queryqueue_t::size_type length =
m_Queue.Length();
333 for(; current < length; current++) {
354 NS_ENSURE_SUCCESS(rv, rv);
361 NS_ENSURE_TRUE(
m_pEngine, NS_ERROR_NOT_INITIALIZED);
365 return mon.NotifyAll();
370 NS_ENSURE_SUCCESS(rv, rv);
373 NS_ENSURE_SUCCESS(rv, rv);
415 grow(aLength,
sizeof(NATIVE_CHAR_TYPE));
418 grow(aLength,
sizeof(UTF16_CHARTYPE));
420 inline void copy_native(
const NATIVE_CHAR_TYPE *aFrom, PRInt32 aSize) {
422 copy(aFrom, aSize,
sizeof(NATIVE_CHAR_TYPE));
425 inline void copy_utf16(
const UTF16_CHARTYPE *aFrom, PRInt32 aSize) {
427 copy(aFrom, aSize,
sizeof(UTF16_CHARTYPE));
428 ((UTF16_CHARTYPE*)mBuffer)[aSize] = 0;
437 inline void grow(PRInt32 aLength, PRInt32 aCharSize) {
438 int s = ((aLength)+1)*aCharSize;
439 if (mBufferLen < s) {
442 mBuffer = (NATIVE_CHAR_TYPE *)malloc(s);
446 inline void copy(
const void *aFrom, PRInt32 aSize, PRInt32 aCharSize) {
447 memcpy(mBuffer, aFrom, aSize * aCharSize);
449 NATIVE_CHAR_TYPE *mBuffer;
461 #endif // __DATABASE_ENGINE_H__
nsresult PushQueryToQueue(CDatabaseQuery *pQuery, PRBool bPushToFront=PR_FALSE)
NATIVE_CHAR_TYPE * buffer()
nsresult Init(CDatabaseEngine *pEngine, const nsAString &aGUID, sqlite3 *pHandle)
already_AddRefed< QueryProcessorQueue > GetQueueByQuery(CDatabaseQuery *pQuery, PRBool bCreate=PR_FALSE)
CDatabaseEngine * gEngine
fastString encodingConversionBuffer2
fastString substringExtractionBuffer1
NS_DECL_ISUPPORTS NS_DECL_NSIOBSERVER NS_DECL_SBIDATABASEENGINE CDatabaseEngine()
PRInt32 SubmitQueryPrivate(CDatabaseQuery *pQuery)
[USER CODE SHOULD NOT REFERENCE THIS CLASS]
static CDatabaseEngine * GetSingleton()
fastString substringExtractionBuffer2
PRMonitor * m_pQueueMonitor
virtual ~CDatabaseEngine()
NS_DECL_ISUPPORTS QueryProcessorQueue()
already_AddRefed< nsIEventTarget > GetEventTarget()
void grow_utf16(PRInt32 aLength)
already_AddRefed< QueryProcessorQueue > CreateQueueFromQuery(CDatabaseQuery *pQuery)
void grow_native(PRInt32 aLength)
void copy_native(const NATIVE_CHAR_TYPE *aFrom, PRInt32 aSize)
void SQLiteUpdateHook(void *pData, int nOp, const char *pArgA, const char *pArgB, sqlite_int64 nRowID)
nsresult OpenDB(const nsAString &dbGUID, CDatabaseQuery *pQuery, sqlite3 **ppHandle)
void copy_utf16(const UTF16_CHARTYPE *aFrom, PRInt32 aSize)
static void PR_CALLBACK QueryProcessor(CDatabaseEngine *pEngine, QueryProcessorQueue *pQueue)
fastString encodingConversionBuffer1
nsresult PopQueryFromQueue(CDatabaseQuery **ppQuery)
nsresult PrepareForShutdown()
nsCOMPtr< nsIEventTarget > m_pEventTarget
nsresult GetQueueSize(PRUint32 &aSize)
PRInt32 Collate(collationBuffers *aCollationBuffers, const NATIVE_CHAR_TYPE *aStr1, const NATIVE_CHAR_TYPE *aStr2)
nsTArray< CDatabaseQuery * > queryqueue_t
_updateTextAndScrollDataForFrame aData
nsresult CloseDB(sqlite3 *pHandle)
CDatabaseEngine * m_pEngine
Songbird Database Object Definition.