'''
Created on Apr 09, 2011
Modified on Sep 11, 2012
@author: Dilum Bandara
@version: 0.12
@license: Apache License v2.0

   Copyright 2012 H. M. N. Dilum Bandara and Anura P. Jayasumana, Colorado State
   University

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
'''

class QueryMsg(object):
    '''
    Query message class. 
    '''
    def __init__(self, source, query,  validTime = -1, minKey = -1, maxKey = -1\
                 , attToQue = None, msgType = 'Query'):        
        '''        
        @param source: Source address
        @param n: Number of resources to query for
        @param query: List of attribute ranges ['att', min, max]
        @param minKey: Start of query range
        @param maxKey: End of query range
        @param param: Most selective attribute or attribute for sub-query
        @param msgType: Message type - also used as a reply message
        @param validTime: Results need to be newer than this time 
        '''
        self.msgType = msgType
        self.source = source
        self.query = query
        self.validTime = validTime
        self.minKey = minKey
        self.maxKey = maxKey
        self.attToQue = attToQue
        self.hops = 0 #Number of hops
        self.resources = [] #List of nodes IDs satisfying query
        self.numResFound = 0 #Number of resources found so far
        self.success = False #Was query success


    def incrementHops(self):
        '''
        Increment hops
        '''
        self.hops += 1


    def setHops(self, hops):
        '''
        Set number of hops
        @param hops: Hops 
        '''
        self.hops = hops