# Path: wildfind/common/database.py
# def create_database(connection):
#     err = None
# 
#     with connection:
#         try:
#             cmd = 'pragma foreign_keys = 1;'
#             connection.execute(cmd)
#             cmd = 'pragma auto_vacuum = incremental;'
#             connection.execute(cmd)
# 
#             cursor = connection.cursor()
# 
#             cmd = ('select name from sqlite_master where '
#                    'type = "table" and name = "Info"')
#             cursor.execute(cmd)
#             table = cursor.fetchall()
#             if len(table):
#                 __upgrade(cursor)
#                 cmd = 'drop table if exists temp'
#                 cursor.execute(cmd)
#             else:
#                 __create_tables(cursor)
#         except sqlite3.IntegrityError as error:
#             err = 'Database error: {}'.format(error.message)
#         except sqlite3.OperationalError as error:
#             err = 'Database error: {}'.format(error.message)
# 
#     return err
# 
# def name_factory(cursor, row):
#     names = {}
#     for i, column in enumerate(cursor.description):
#         names[column[0]] = row[i]
# 
#     return names
# 
# Path: wildfind/harrier/events.py
# SCAN_START, SCAN_DONE, \
#     GPS_OPEN, GPS_LOC, GPS_SATS, GPS_ERR, \
#     STATUS_IDLE, STATUS_WAIT, STATUS_CAPTURE, STATUS_PROCESS, \
#     INFO, WARN, ERR = range(13)
# class Event(object):
# class Post(object):
#     def __init__(self, eventType, **kwargs):
#     def get_type(self):
#     def get_arg(self, arg):
#     def get_args(self):
#     def __init__(self, queue):
#     def __post(self, event, delay=0):
#     def status(self, eventType):
#     def scan_start(self, delay=0):
#     def scan_done(self, collars=None, timeStamp=None):
#     def gps_open(self, delay):
#     def gps_location(self, location):
#     def gps_satellites(self, satellites):
#     def gps_error(self, error):
#     def error(self, error):
#     def warning(self, warning):
#     def info(self, info):


import Queue
import ctypes
import os
import platform
import sqlite3
import threading
import time
from wildfind.common.database import create_database, name_factory
from wildfind.harrier import events

        while True:
            if not self._queue.empty():
                event = self._queue.get()
                eventType = event.get_type()

                if eventType == GET_SCANS:
                    callback = event.get_arg('callback')
                    self.__get_scans(callback)
                elif eventType == ADD_SIGNAL:
                    self.__add_signal(**event.get_args())
                elif eventType == GET_SIGNALS:
                    callback = event.get_arg('callback')
                    self.__get_signals(callback)
                elif eventType == ADD_LOG:
                    self.__add_log(**event.get_args())
                elif eventType == GET_LOG:
                    callback = event.get_arg('callback')
                    self.__get_log(callback)
                elif eventType == CLOSE:
                    break
            else:
                try:
                    time.sleep(0.1)
                except IOError:
                    pass

        self._conn.close()

    def append_signal(self, timeStamp, signal, frequency, survey):

# Path: wildfind/common/database.py
# def create_database(connection):
#     err = None
# 
#     with connection:
#         try:
#             cmd = 'pragma foreign_keys = 1;'
#             connection.execute(cmd)
#             cmd = 'pragma auto_vacuum = incremental;'
#             connection.execute(cmd)
# 
#             cursor = connection.cursor()
# 
#             cmd = ('select name from sqlite_master where '
#                    'type = "table" and name = "Info"')
#             cursor.execute(cmd)
#             table = cursor.fetchall()
#             if len(table):
#                 __upgrade(cursor)
#                 cmd = 'drop table if exists temp'
#                 cursor.execute(cmd)
#             else:
#                 __create_tables(cursor)
#         except sqlite3.IntegrityError as error:
#             err = 'Database error: {}'.format(error.message)
#         except sqlite3.OperationalError as error:
#             err = 'Database error: {}'.format(error.message)
# 
#     return err
# 
# def name_factory(cursor, row):
#     names = {}
#     for i, column in enumerate(cursor.description):
#         names[column[0]] = row[i]
# 
#     return names
# 
# Path: wildfind/harrier/events.py
# SCAN_START, SCAN_DONE, \
#     GPS_OPEN, GPS_LOC, GPS_SATS, GPS_ERR, \
#     STATUS_IDLE, STATUS_WAIT, STATUS_CAPTURE, STATUS_PROCESS, \
#     INFO, WARN, ERR = range(13)
# class Event(object):
# class Post(object):
#     def __init__(self, eventType, **kwargs):
#     def get_type(self):
#     def get_arg(self, arg):
#     def get_args(self):
#     def __init__(self, queue):
#     def __post(self, event, delay=0):
#     def status(self, eventType):
#     def scan_start(self, delay=0):
#     def scan_done(self, collars=None, timeStamp=None):
#     def gps_open(self, delay):
#     def gps_location(self, location):
#     def gps_satellites(self, satellites):
#     def gps_error(self, error):
#     def error(self, error):
#     def warning(self, warning):
#     def info(self, info):


# Path: wildfind/harrier/database.py
import Queue
import ctypes
import os
import platform
import sqlite3
import threading
import time
from wildfind.common.database import create_database, name_factory
from wildfind.harrier import events


        while True:
            if not self._queue.empty():
                event = self._queue.get()
                eventType = event.get_type()

                if eventType == GET_SCANS:
                    callback = event.get_arg('callback')
                    self.__get_scans(callback)
                elif eventType == ADD_SIGNAL:
                    self.__add_signal(**event.get_args())
                elif eventType == GET_SIGNALS:
                    callback = event.get_arg('callback')
                    self.__get_signals(callback)
                elif eventType == ADD_LOG:
                    self.__add_log(**event.get_args())
                elif eventType == GET_LOG:
                    callback = event.get_arg('callback')
                    self.__get_log(callback)
                elif eventType == CLOSE:
                    break
            else:
                try:
                    time.sleep(0.1)
                except IOError:
                    pass

        self._conn.close()

    def append_signal(self, timeStamp, signal, frequency, survey):

        event = events.Event(ADD_SIGNAL,