core: backend autoconnection:
A new Connection/autoconnect_backend param can be set for a profile or component to be started automatically with backend. This is specially useful for components, but can be useful for client profile too (e.g. on Android we need to start profile with backend to get notifications, this part will come with following commits). The new Sqlite.getIndParamValues method allows to retrieve the same parameters for all profiles.
This commit is contained in:
parent
d73fed6f24
commit
1d91db6f2c
1 changed files with 81 additions and 29 deletions
|
|
@ -196,8 +196,10 @@ class SqliteStorage(object):
|
|||
|
||||
@param db_filename: full path to the Sqlite database
|
||||
"""
|
||||
self.initialized = defer.Deferred() # triggered when memory is fully initialised and ready
|
||||
self.profiles = {} # we keep cache for the profiles (key: profile name, value: profile id)
|
||||
# triggered when memory is fully initialised and ready
|
||||
self.initialized = defer.Deferred()
|
||||
# we keep cache for the profiles (key: profile name, value: profile id)
|
||||
self.profiles = {}
|
||||
|
||||
log.info(_("Connecting database"))
|
||||
new_base = not os.path.exists(db_filename) # do we have to create the database ?
|
||||
|
|
@ -231,10 +233,10 @@ class SqliteStorage(object):
|
|||
init_defer.addCallback(self.commitStatements)
|
||||
|
||||
def fillProfileCache(ignore):
|
||||
d = self.dbpool.runQuery("SELECT profile_id, entry_point FROM components").addCallback(self._cacheComponentsAndProfiles)
|
||||
d.chainDeferred(self.initialized)
|
||||
return self.dbpool.runQuery("SELECT profile_id, entry_point FROM components").addCallback(self._cacheComponentsAndProfiles)
|
||||
|
||||
init_defer.addCallback(fillProfileCache)
|
||||
init_defer.chainDeferred(self.initialized)
|
||||
|
||||
def commitStatements(self, statements):
|
||||
|
||||
|
|
@ -387,10 +389,26 @@ class SqliteStorage(object):
|
|||
@param profile: %(doc_profile)s
|
||||
@return: deferred
|
||||
"""
|
||||
d = self.dbpool.runQuery("SELECT value FROM param_ind WHERE category=? AND name=? AND profile_id=?", (category, name, self.profiles[profile]))
|
||||
d = self.dbpool.runQuery(
|
||||
"SELECT value FROM param_ind WHERE category=? AND name=? AND profile_id=?",
|
||||
(category, name, self.profiles[profile]))
|
||||
d.addCallback(self.__getFirstResult)
|
||||
return d
|
||||
|
||||
async def getIndParamValues(self, category, name):
|
||||
"""Ask database for the individual values of a parameter for all profiles
|
||||
|
||||
@param category: category of the parameter
|
||||
@param name: name of the parameter
|
||||
@return dict: profile => value map
|
||||
"""
|
||||
result = await self.dbpool.runQuery(
|
||||
"SELECT profiles.name, param_ind.value FROM param_ind JOIN profiles ON "
|
||||
"param_ind.profile_id = profiles.id WHERE param_ind.category=? "
|
||||
"and param_ind.name=?",
|
||||
(category, name))
|
||||
return dict(result)
|
||||
|
||||
def setGenParam(self, category, name, value):
|
||||
"""Save the general parameters in database
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue