'''
Created on Nov 2, 2011
Modified on Mar 6, 2012
@version: 0.11
@author: Dilum Bandara
@email: dilumb@engr.colostate.edu
@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.
'''

from Location import Location

class CCNInterest(object):
    '''
    CCN Interest message class
    Extended to support subscription based queries
    '''

    def __init__(self, name, realName, minLoc, maxLoc, app, time, \
                 dataType = None, numRadars = -1, bitMap = [], \
                 dataRequest = True):
        '''
        Constructor. Maintain individual elements of name to speed up processing
        @param name: Content name. /x1/y1/x2/y2/application/time or 
        /x1/y1/x2/y2/application/datatype/numRadars/time - time may be skipped
        @param realName: This is the actual content name. name may skip some 
        parts to simplify implementation
        @param minLoc: bottom left corner
        @param maxLoc: top right corner
        @param app: Application
        @param time: Need data generated after this time
        @param dataType: Application layer data type (reflectivity, velocity) 
        @param numRadars: Number of radars required (optional)
        @param bitMap: bit map 
        @param dataRequest: This message is requesting data  
        '''
        self.msgType = 'CCNInt'
        self.name = name
        self.realName = realName         
        self.minLoc = minLoc
        self.maxLoc = maxLoc
        self.loc = Location((minLoc.x + maxLoc.x)/2.0, (minLoc.y + maxLoc.y)/2.0)
        self.app = app
        self.time = time
        self.dataType = dataType
        self.numRadars = numRadars
        self.bitMap = bitMap
        self.hops = 0 #For stat only
        self.direct = False #Is this message send directly
        self.size = float(len(realName) * 8) #in bits
        self.dataRequest = dataRequest


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


    def setDirect(self):
        '''
        Set this message as being send direct between 2 nodes
        '''
        self.direct = True