<commit_before>'''
@author: arcra
'''

import threading, time, types, Queue
import SharedVariables, ParallelSenders
from Messages import Message, Command, Response
from ConnectionManager import ConnectionManager
from CommandParser import CommandParser

ParallelSender = ParallelSenders.ParallelSender

SharedVarTypes = SharedVariables.SharedVarTypes
SubscriptionTypes = SharedVariables.SubscriptionTypes
ReportTypes = SharedVariables.ReportTypes

__initialized = False

__started = False
__startedLock = threading.Lock()

__ready = False
__readyLock = threading.Lock()

_subscriptionHandlersLock = threading.Lock()
_subscriptionHandlers = {}

_incomingMessages = Queue.Queue(20)
_receivedCommands = Queue.Queue(20)

_receivedResponses = {}
_responsesLock = threading.Lock()

_sentCommands = set([])
_commandsLock = threading.Lock()

def Initialize(port, functionMap={}, asyncHandler = None):
    global __executors, __connMan, __parser, __p, __initialized, __ready
    
    __executors = { 'busy' : (lambda x: Response('busy'), False),
                      'ready' : (__isReady, False),
                      'alive' : (lambda x: Response('alive', True), False) }

    for m in functionMap:
        if isinstance(functionMap[m], types.FunctionType):
            __executors[m] = (functionMap[m], False)
        elif isinstance(functionMap[m], tuple):
            __executors[m] = functionMap[m]
        else:
            print 'Element in function map is not a function nor a tuple: ' + repr(functionMap[m])
    
    __connMan = ConnectionManager(port)
    __parser = CommandParser(asyncHandler)
    
    __p = threading.Thread(target=__MainThread)
    __p.daemon = True
    
    __initialized = True

def Start():
    global __p, __connMann, __parser, __initialized, __started, __startedLock
    
    if not __initialized:
        print 'pyRobotics need to be initialized before starting.'
        return
    
    __parser.Start()
    __connMan.Start()
    __p.start()
    
    __startedLock.acquire()
    __started = True
    __startedLock.release()

def SetReady(val):
    global __ready, __readyLock
    
    __readyLock.acquire()
    __ready = val
    __readyLock.release()

def __isReady(c):
    global __ready, __readyLock
    
    __readyLock.acquire()
    ready = __ready
    __readyLock.release()
    <commit_msg>Modified BB.SetReady function to have True as default value.<commit_after>'''
@author: arcra
'''

import threading, time, types, Queue
import SharedVariables, ParallelSenders
from Messages import Message, Command, Response
from ConnectionManager import ConnectionManager
from CommandParser import CommandParser

ParallelSender = ParallelSenders.ParallelSender

SharedVarTypes = SharedVariables.SharedVarTypes
SubscriptionTypes = SharedVariables.SubscriptionTypes
ReportTypes = SharedVariables.ReportTypes

__initialized = False

__started = False
__startedLock = threading.Lock()

__ready = False
__readyLock = threading.Lock()

_subscriptionHandlersLock = threading.Lock()
_subscriptionHandlers = {}

_incomingMessages = Queue.Queue(20)
_receivedCommands = Queue.Queue(20)

_receivedResponses = {}
_responsesLock = threading.Lock()

_sentCommands = set([])
_commandsLock = threading.Lock()

def Initialize(port, functionMap={}, asyncHandler = None):
    global __executors, __connMan, __parser, __p, __initialized, __ready
    
    __executors = { 'busy' : (lambda x: Response('busy'), False),
                      'ready' : (__isReady, False),
                      'alive' : (lambda x: Response('alive', True), False) }

    for m in functionMap:
        if isinstance(functionMap[m], types.FunctionType):
            __executors[m] = (functionMap[m], False)
        elif isinstance(functionMap[m], tuple):
            __executors[m] = functionMap[m]
        else:
            print 'Element in function map is not a function nor a tuple: ' + repr(functionMap[m])
    
    __connMan = ConnectionManager(port)
    __parser = CommandParser(asyncHandler)
    
    __p = threading.Thread(target=__MainThread)
    __p.daemon = True
    
    __initialized = True

def Start():
    global __p, __connMann, __parser, __initialized, __started, __startedLock
    
    if not __initialized:
        print 'pyRobotics need to be initialized before starting.'
        return
    
    __parser.Start()
    __connMan.Start()
    __p.start()
    
    __startedLock.acquire()
    __started = True
    __startedLock.release()

def SetReady(val=True):
    global __ready, __readyLock
    
    __readyLock.acquire()
    __ready = val
    __readyLock.release()

def __isReady(c):
    global __ready, __readyLock
    
    __readyLock.acquire()
    ready = __ready
    __readyLock.release()
    
{'fraction_non_alphanumeric': 0.09212765957446808, 'fraction_numerical': 0.001702127659574468, 'mean_word_length': 3.542028985507246, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6564664', 'n_tokens_mistral': 1388, 'n_tokens_neox': 1371, 'n_words': 346}