# Path: umit/icm/agent/logger.py
# LOGLEVEL = 'DEBUG'
# 
# Path: umit/icm/agent/rpc/message.py
# MAX_MESSAGE_LENGTH = 1024 * 1024   # max message length is 1M
# class MalformedMessageError(Exception):
# class RawMessage(object):
#     def __init__(self):
#     def fill(self, data):
# 
# Path: umit/icm/agent/rpc/MessageFactory.py
# class MessageFactory(object):
#     """"""
#     _reader = BinaryReader()
#     _writer = BinaryWriter()
# 
#     #----------------------------------------------------------------------
#     #def __init__(self):
#         #"""Constructor"""
# 
#     @classmethod
#     def create(cls, msg_type):
#         return message_creator[msg_type]()
# 
#     @classmethod
#     def encode(cls, message):
#         cls._writer.reset()
#         msg_type = message.DESCRIPTOR.name
#         msg_type_id = message_type_to_id[msg_type]
#         msg_str = message.SerializeToString()
#         cls._writer.writeInt32(msg_type_id)
#         cls._writer.writeFixedLengthString(msg_str, len(msg_str))
#         return cls._writer.getString()
# 
#     @classmethod
#     def decode(cls, str_):
#         cls._reader.setString(str_)
#         msg_type_id = cls._reader.readInt32()
#         msg_type = message_id_to_type[msg_type_id]
#         message = cls.create(msg_type)
#         msg_str = cls._reader.readFixedLengthString(len(str_)-4)
#         message.ParseFromString(msg_str)
#         return message
# 
#     @classmethod
#     def encrypt(cls, str_):
#         pass
# 
#     @classmethod
#     def decrypt(cls, str_):
#         pass


import base64
import time
    import time
from umit.icm.agent.logger import g_logger
from umit.icm.agent.Global import *
from umit.icm.agent.rpc.message import WebsiteReportDetail, ServiceReportDetail
from umit.icm.agent.rpc.MessageFactory import MessageFactory
    from umit.icm.agent.rpc.message import *

        if event_entry.WebsiteReport:
            wr_str = base64.b64encode(
                MessageFactory.encode(event_entry.WebsiteReport))
        sr_str = None
        if event_entry.ServiceReport:
            sr_str = base64.b64encode(
                MessageFactory.encode(event_entry.ServiceReport))
        sql_stmt = "insert into events (test_type, event_type, time, "\
                   "since_time, locations, website_report, service_report) "\
                   "values ('%s', '%s', %d, %d, '%s', '%s', '%s')" % \
                   (event_entry.TestType,
                    event_entry.EventType,
                    event_entry.TimeUTC,
                    event_entry.SinceTimeUTC,
                    loc_str, wr_str, sr_str)

        g_db_helper.execute(sql_stmt)
        g_db_helper.commit()
        #g_logger.debug("Save report '%s' to table '%s'." % (report_entry.ID,
                                                            #table_name))


if __name__ == "__main__":
    event_entry = EventEntry()
    event_entry.TestType = 'WEB'
    event_entry.EventType = 'CENSOR'
    event_entry.TimeUTC = int(time.time())
    event_entry.SinceTimeUTC = int(time.time())
    event_entry.Locations.append((10.10, 20.20))
    event_entry.Locations.append((30.30, 40.40))

# Path: umit/icm/agent/logger.py
# LOGLEVEL = 'DEBUG'
# 
# Path: umit/icm/agent/rpc/message.py
# MAX_MESSAGE_LENGTH = 1024 * 1024   # max message length is 1M
# class MalformedMessageError(Exception):
# class RawMessage(object):
#     def __init__(self):
#     def fill(self, data):
# 
# Path: umit/icm/agent/rpc/MessageFactory.py
# class MessageFactory(object):
#     """"""
#     _reader = BinaryReader()
#     _writer = BinaryWriter()
# 
#     #----------------------------------------------------------------------
#     #def __init__(self):
#         #"""Constructor"""
# 
#     @classmethod
#     def create(cls, msg_type):
#         return message_creator[msg_type]()
# 
#     @classmethod
#     def encode(cls, message):
#         cls._writer.reset()
#         msg_type = message.DESCRIPTOR.name
#         msg_type_id = message_type_to_id[msg_type]
#         msg_str = message.SerializeToString()
#         cls._writer.writeInt32(msg_type_id)
#         cls._writer.writeFixedLengthString(msg_str, len(msg_str))
#         return cls._writer.getString()
# 
#     @classmethod
#     def decode(cls, str_):
#         cls._reader.setString(str_)
#         msg_type_id = cls._reader.readInt32()
#         msg_type = message_id_to_type[msg_type_id]
#         message = cls.create(msg_type)
#         msg_str = cls._reader.readFixedLengthString(len(str_)-4)
#         message.ParseFromString(msg_str)
#         return message
# 
#     @classmethod
#     def encrypt(cls, str_):
#         pass
# 
#     @classmethod
#     def decrypt(cls, str_):
#         pass


# Path: umit/icm/agent/core/EventManager.py
import base64
import time
    import time
from umit.icm.agent.logger import g_logger
from umit.icm.agent.Global import *
from umit.icm.agent.rpc.message import WebsiteReportDetail, ServiceReportDetail
from umit.icm.agent.rpc.MessageFactory import MessageFactory
    from umit.icm.agent.rpc.message import *

        if event_entry.WebsiteReport:
            wr_str = base64.b64encode(
                MessageFactory.encode(event_entry.WebsiteReport))
        sr_str = None
        if event_entry.ServiceReport:
            sr_str = base64.b64encode(
                MessageFactory.encode(event_entry.ServiceReport))
        sql_stmt = "insert into events (test_type, event_type, time, "\
                   "since_time, locations, website_report, service_report) "\
                   "values ('%s', '%s', %d, %d, '%s', '%s', '%s')" % \
                   (event_entry.TestType,
                    event_entry.EventType,
                    event_entry.TimeUTC,
                    event_entry.SinceTimeUTC,
                    loc_str, wr_str, sr_str)

        g_db_helper.execute(sql_stmt)
        g_db_helper.commit()
        #g_logger.debug("Save report '%s' to table '%s'." % (report_entry.ID,
                                                            #table_name))


if __name__ == "__main__":
    event_entry = EventEntry()
    event_entry.TestType = 'WEB'
    event_entry.EventType = 'CENSOR'
    event_entry.TimeUTC = int(time.time())
    event_entry.SinceTimeUTC = int(time.time())
    event_entry.Locations.append((10.10, 20.20))
    event_entry.Locations.append((30.30, 40.40))

    event_entry.WebsiteReport = WebsiteReportDetail()
