# Path: sim/sim_shell.py
# def setupLogger():
#     def __init__(self, simCtrl, interactive=False):
#     def select_sim_card(self, simId):
#     def apdu(self, data, channel=None, mode=None):
#     def set_active_channel(self, channel):
#     def query_code_status(self, name):
#     def force_security_codes(self, state):
#     def verify_code(self, name):
#     def validate_pin1(self, state):
#     def get_plmn(self):
#     def set_plmn(self, value):
#     def pwd(self):
#     def cd(self, path):
#     def ls(self):
#     def read(self, path):
#     def readi(self, path):
#     def write(self, path, data):
#     def writei(self, path, value):
#     def create(self, path, param=None):
#     def create_arr(self, path, fileParam=None):
#     def delete(self, path):
#     def resize(self, path, newFileSize, fillPattern=None):
#     def extend(self, path, sizeToExtend):
#     def get_ust(self, serviceId):
#     def set_ust(self, serviceId, value):
#     def open_channel(self, originChannel, targetChannel):
#     def close_channel(self, originChannel, targetChannel):
#     def log_level(self, level):
#     def backup(self):
#     def sat(self, param, value=None):
#     def updateInteractive(self, interactive):
#     def queryUser(self, question, default=''):
#     def verifyCode(self, pinId):
#     def updatePrompt(self):
#     def responseOk(self, out=None):
#     def responseNok(self, out=None):
#     def getValue(self, cmd):
#     def getIntValue(self, cmd):
#     def statusOk(self, status):
#     def assertOk(self, status, out=None):
#     def assertNok(self, status, out=None):
#     def checkFileConditions(self, path, accessMode):
#     def modifyArrConditions(self, arrPath, arrRecord, arrValue, accessMode):
#     def restoreArrConditions(self, arrPath, arrRecord, previousArrValue):
#     def restorePath(self, path):
#     def selectFile(self, path):
#     def getAbsolutePath(self, pathName):
#     def verifyCondition(self, condition):
#     def verifyConditions(self, conditions, mode):
#     def deleteRaw(self, path, accessMode=types.AM_EF_DELETE):
#     def readRaw(self, path, forceAccess=False):
#     def writeRaw(self, path, data):
#     def resizeRaw(self, path, newFileSize, fillPattern):
#     def extendRaw(self, path, sizeToExtend):
#     def createRaw(self, path, fileParam):
#     def createFile(self, path, fileParam=None):
#     def createDirectory(self, path, fileParam=None):
#     def createArr(self, path, fileParam):
#     def _backup(self, path, node):
#     def __init__(self, ss, path, accessMode, forceAccess=True):
#     def __enter__(self):
#     def __exit__(self, type, value, traceback):
# class SimShell(object):
# class FileAccessCondition(object):


import logging
import time
import multiprocessing
import Queue
import dbus
import dbus.service
import gevent
import sys
from dbus.mainloop.glib import DBusGMainLoop
from gi.repository import GLib
from gevent import select as geventSelect
from sim import sim_shell

        DBusGMainLoop(set_as_default=True)
        dbusService = SessionDBus(self.taskQueue, self.resultQueue)

        try:
            GLib.MainLoop().run()
        except KeyboardInterrupt:
            logging.debug("\nThe MainLoop will close...")
            GLib.MainLoop().quit()
        return


class SessionDBus(dbus.service.Object, sim_shell.SimShell):
    def __init__(self, taskQueue, resultQueue):
        self.taskQueue = taskQueue
        self.resultQueue = resultQueue
        bus_name = dbus.service.BusName('org.sim.simlab', bus=dbus.SessionBus())
        dbus.service.Object.__init__(self, bus_name, '/org/sim/simlab')

    """
    Dynamically create functions, based on sim_shell.SimShell.commands. They are exported to D-Bus.
    """
    functionTemplate = "" \
                       "def command_name(self,args=None): \n" \
                       "    self.taskQueue.put('command_name ' + args) \n" \
                       "    return self.resultQueue.get() \n" \
                       "command_name = dbus.service.method('org.sim.simlab')(command_name)   "
    for command in sim_shell.SimShell.commands:
        functionCode = functionTemplate.replace('command_name', command)
        # check how many parameters takes original function

# Path: sim/sim_shell.py
# def setupLogger():
#     def __init__(self, simCtrl, interactive=False):
#     def select_sim_card(self, simId):
#     def apdu(self, data, channel=None, mode=None):
#     def set_active_channel(self, channel):
#     def query_code_status(self, name):
#     def force_security_codes(self, state):
#     def verify_code(self, name):
#     def validate_pin1(self, state):
#     def get_plmn(self):
#     def set_plmn(self, value):
#     def pwd(self):
#     def cd(self, path):
#     def ls(self):
#     def read(self, path):
#     def readi(self, path):
#     def write(self, path, data):
#     def writei(self, path, value):
#     def create(self, path, param=None):
#     def create_arr(self, path, fileParam=None):
#     def delete(self, path):
#     def resize(self, path, newFileSize, fillPattern=None):
#     def extend(self, path, sizeToExtend):
#     def get_ust(self, serviceId):
#     def set_ust(self, serviceId, value):
#     def open_channel(self, originChannel, targetChannel):
#     def close_channel(self, originChannel, targetChannel):
#     def log_level(self, level):
#     def backup(self):
#     def sat(self, param, value=None):
#     def updateInteractive(self, interactive):
#     def queryUser(self, question, default=''):
#     def verifyCode(self, pinId):
#     def updatePrompt(self):
#     def responseOk(self, out=None):
#     def responseNok(self, out=None):
#     def getValue(self, cmd):
#     def getIntValue(self, cmd):
#     def statusOk(self, status):
#     def assertOk(self, status, out=None):
#     def assertNok(self, status, out=None):
#     def checkFileConditions(self, path, accessMode):
#     def modifyArrConditions(self, arrPath, arrRecord, arrValue, accessMode):
#     def restoreArrConditions(self, arrPath, arrRecord, previousArrValue):
#     def restorePath(self, path):
#     def selectFile(self, path):
#     def getAbsolutePath(self, pathName):
#     def verifyCondition(self, condition):
#     def verifyConditions(self, conditions, mode):
#     def deleteRaw(self, path, accessMode=types.AM_EF_DELETE):
#     def readRaw(self, path, forceAccess=False):
#     def writeRaw(self, path, data):
#     def resizeRaw(self, path, newFileSize, fillPattern):
#     def extendRaw(self, path, sizeToExtend):
#     def createRaw(self, path, fileParam):
#     def createFile(self, path, fileParam=None):
#     def createDirectory(self, path, fileParam=None):
#     def createArr(self, path, fileParam):
#     def _backup(self, path, node):
#     def __init__(self, ss, path, accessMode, forceAccess=True):
#     def __enter__(self):
#     def __exit__(self, type, value, traceback):
# class SimShell(object):
# class FileAccessCondition(object):


# Path: util/dbus_ctrl.py
import logging
import time
import multiprocessing
import Queue
import dbus
import dbus.service
import gevent
import sys
from dbus.mainloop.glib import DBusGMainLoop
from gi.repository import GLib
from gevent import select as geventSelect
from sim import sim_shell


        DBusGMainLoop(set_as_default=True)
        dbusService = SessionDBus(self.taskQueue, self.resultQueue)

        try:
            GLib.MainLoop().run()
        except KeyboardInterrupt:
            logging.debug("\nThe MainLoop will close...")
            GLib.MainLoop().quit()
        return


class SessionDBus(dbus.service.Object, sim_shell.SimShell):
    def __init__(self, taskQueue, resultQueue):
        self.taskQueue = taskQueue
        self.resultQueue = resultQueue
        bus_name = dbus.service.BusName('org.sim.simlab', bus=dbus.SessionBus())
        dbus.service.Object.__init__(self, bus_name, '/org/sim/simlab')

    """
    Dynamically create functions, based on sim_shell.SimShell.commands. They are exported to D-Bus.
    """
    functionTemplate = "" \
                       "def command_name(self,args=None): \n" \
                       "    self.taskQueue.put('command_name ' + args) \n" \
                       "    return self.resultQueue.get() \n" \
                       "command_name = dbus.service.method('org.sim.simlab')(command_name)   "
    for command in sim_shell.SimShell.commands:
        functionCode = functionTemplate.replace('command_name', command)
        # check how many parameters takes original function

        argumentCount = getattr(sim_shell.SimShell, command).func_code.co_argcount