From c79ef924abea4c3138594bbbd494a7144c2040ee Mon Sep 17 00:00:00 2001 From: Manuel Coutand Date: Tue, 17 Apr 2012 11:51:36 +0200 Subject: Bug 376883 - ContextQuery service is missing --- python/src/tcf/services/contextquery.py | 65 ++++++++++++++++++++++ .../src/tcf/services/remote/ContextQueryProxy.py | 59 ++++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 python/src/tcf/services/contextquery.py create mode 100644 python/src/tcf/services/remote/ContextQueryProxy.py (limited to 'python/src') diff --git a/python/src/tcf/services/contextquery.py b/python/src/tcf/services/contextquery.py new file mode 100644 index 000000000..c93827a0e --- /dev/null +++ b/python/src/tcf/services/contextquery.py @@ -0,0 +1,65 @@ +# ***************************************************************************** +# * Copyright (c) 2012 Wind River Systems, Inc. and others. +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Wind River Systems - initial API and implementation +# ***************************************************************************** + +""" +TCF ContextQuery service interface. +""" + +from tcf import services + +# Service name. +NAME = "ContextQuery" + + +class ContextQueryService(services.Service): + def getName(self): + return NAME + + def query(self, querystr, done): + """ + @param querystr - context query to be executed. + @param done - command result call back object. + @return - pending command handle. + @see DoneQuery + """ + raise NotImplementedError("Abstract method") + + def getAttrNames(self, done): + """ + @param done - command result call back object. + @return - pending command handle. + @see DoneGetAttrNames + """ + raise NotImplementedError("Abstract method") + + +class DoneQuery(object): + "Call back interface for 'query' command." + def doneQuery(self, token, error, ctxList): + """ + Called when 'query' command is done. + @param token - command handle. + @param error - error object or None. + @param ctxList - IDs of contexts matching the query. + """ + pass + + +class DoneGetAttrNames(object): + "Call back interface for 'getAttrNames' command." + def doneGetAttrNames(self, token, error, attrNameList): + """ + Called when 'getAttrNames' command is done. + @param token - command handle. + @param error - error object or None. + @param attrNameList - List of the attributes supported by the agent. + """ + pass diff --git a/python/src/tcf/services/remote/ContextQueryProxy.py b/python/src/tcf/services/remote/ContextQueryProxy.py new file mode 100644 index 000000000..2d3a420e6 --- /dev/null +++ b/python/src/tcf/services/remote/ContextQueryProxy.py @@ -0,0 +1,59 @@ +# ***************************************************************************** +# * Copyright (c) 2012 Wind River Systems, Inc. and others. +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Wind River Systems - initial API and implementation +# ***************************************************************************** + +from tcf.services import contextquery +from tcf.channel.Command import Command + + +class ContextQueryProxy(contextquery.ContextQueryService): + def __init__(self, channel): + self.channel = channel + self.listeners = {} + + def query(self, querystr, done): + done = self._makeCallback(done) + service = self + + class QueryCommand(Command): + + def __init__(self): + super(QueryCommand, self).__init__(service.channel, service, + "query", (querystr,)) + + def done(self, error, args): + res = None + if not error: + assert len(args) == 2 + error = self.toError(args[0]) + res = args[1] + done.doneQuery(self.token, error, res) + return QueryCommand().token + + def getAttrNames(self, done): + done = self._makeCallback(done) + service = self + + class GetAttrNamesCommand(Command): + + def __init__(self): + super(GetAttrNamesCommand, self).__init__(service.channel, + service, + "getAttrNames", + None) + + def done(self, error, args): + res = None + if not error: + assert len(args) == 2 + error = self.toError(args[0]) + res = args[1] + done.doneGetAttrNames(self.token, error, res) + return GetAttrNamesCommand().token -- cgit v1.2.3