'''
Created on Sep 3, 2012
@version: 0.1
@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.
'''


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

    def __init__(self, name, realName, minLoc, maxLoc, genTime, dataType = None\
             , sensorID = -1, data = None, expireTime = -1, hops = 0):
        '''
        Constructor. Maintain individual elements of name to speed up processing
        @param name: Content name. Should generally support following format: 
        /x1/y1/x2/y2/application/time
        @param name: Real name with all the parts of name 
        @param minLoc: bottom left corner
        @param maxLoc: top right corner
        @param genTime: (Need) data generated at or after this time
        @param dataType: Application layer data type (reflectivity, velocity)
        @param sensorID: Sensor ID if sensor data are advertised using interest 
        messages
        @param data: Sensor data if advertised using interest messages
        @param expireTime: Data should expire after this time
        @param hops: Hop count if this interest message is issued/generated as 
        a consequence of another    
        '''
        self.msgType = 'CCNI' #CCN interest
        self.name = name
        self.realName = realName
        self.minLoc = minLoc
        self.maxLoc = maxLoc
        self.genTime = genTime
        self.dataType = dataType
        self.sensorID = sensorID
        self.data = data
        self.expireTime = expireTime
        self.hops = hops #For stat only
        self.size = float(len(realName) * 8) #in bits
        self.loc = []
        for i in range(len(minLoc)):
            self.loc.append((minLoc[i] + maxLoc[i])/2.0)


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