示例#1
0
    def eReturnOnSpeaker(self, sType, sMess, sOrigin):
        """
        """
        if sType not in lKNOWN_TOPICS:
            sRetval = "eReturnOnSpeaker: oSpeakerChannel unhandled topic " +sMess
            vError(sRetval)
            return sRetval

        assert sOrigin, "eReturnOnSpeaker: oSpeakerChannel empty sOrigin"
        lOrigin = sOrigin.split("|")
        assert lOrigin, "eReturnOnSpeaker: oSpeakerChannel empty lOrigin"
        # 'json' was in here
        assert lOrigin[0] in ['eval', 'cmd', 'exec'], \
            "eReturnOnSpeaker: oSpeakerChannel not cmd " +sOrigin
        # This message is a reply in a cmd
        sMark = lOrigin[3]
        assert sMark, "eReturnOnSpeaker: lOrigin[3] is null: " +repr(lOrigin)
        lMess = sMess.split("|")
        assert lMess[0] == 'retval', \
            "eReturnOnSpeaker: lMess[0] should be retval: " +repr(lMess)
        # these now should be equal
        lMess[3] = sMark
        # Replace the mark in the reply with the mark in the cmd
        sMess = '|'.join(lMess)

        return self.eSendOnSpeaker(sType, sMess)
示例#2
0
    def eReturnOnSpeaker(self, sType, sMess, sOrigin):
        """
        """
        if sType not in lKNOWN_TOPICS:
            sRetval = "eReturnOnSpeaker: oSpeakerChannel unhandled topic " + sMess
            vError(sRetval)
            return sRetval

        assert sOrigin, "eReturnOnSpeaker: oSpeakerChannel empty sOrigin"
        lOrigin = sOrigin.split("|")
        assert lOrigin, "eReturnOnSpeaker: oSpeakerChannel empty lOrigin"
        # 'json' was in here
        assert lOrigin[0] in ['eval', 'cmd', 'exec'], \
            "eReturnOnSpeaker: oSpeakerChannel not cmd " +sOrigin
        # This message is a reply in a cmd
        sMark = lOrigin[3]
        assert sMark, "eReturnOnSpeaker: lOrigin[3] is null: " + repr(lOrigin)
        lMess = sMess.split("|")
        assert lMess[0] == 'retval', \
            "eReturnOnSpeaker: lMess[0] should be retval: " +repr(lMess)
        # these now should be equal
        lMess[3] = sMark
        # Replace the mark in the reply with the mark in the cmd
        sMess = '|'.join(lMess)

        return self.eSendOnSpeaker(sType, sMess)
示例#3
0
def iMain():
    # lGetOptionsArgs adds sMt4Dir/MQL4/Python to the sys.path
    (
        oOptions,
        lArgs,
    ) = lGetOptionsArgs()
    # so lGetOptionsArgs must be called before this import
    from ZmqBinListener import ZmqBinMixin

    if not lArgs:
        # subscribe to everything
        lArgs = ['']
    lTopics = lArgs

    oMixin = None
    try:
        # sChartId is in oOptions
        oMixin = ZmqBinMixin(**oOptions.__dict__)
        oMixin.eConnectToSubPub(lTopics, iDir=zmq.SUB)
        oMixin.eConnectToReqRep(iDir=zmq.REQ)

        i = 0
        while True:

            i += 1
            sys.stderr.write("Command: ")
            sRequest = sys.stdin.readline().strip()
            if not sRequest: break

            if oOptions.sExecType == "default":
                sType = sDefaultExecType(sRequest)
            elif oOptions.sExecType == "exec":
                # execs are executed immediately and return a result on the wire
                # They're things that take less than a tick to evaluate
                sType = "exec"
            else:
                sType = "cmd"
            # only exec really works right now - cmd misses the retval sometimes
            sType = "exec"

            sMarkIn = sMakeMark()
            gRetval = oMixin.gCmdExec(sMarkIn, sRequest, sType, oOptions)
            print gRetval

    except KeyboardInterrupt:
        if oOptions and oOptions.iDebugLevel >= 1:
            vInfo("exiting")

    except Exception as e:
        vError(str(e) +"\n" + \
               traceback.format_exc(10) +"\n")
        sys.stdout.flush()
        sys.exc_clear()

    finally:
        if oMixin:
            oMixin.bCloseContextSockets()

    return 0
示例#4
0
def iMain():
    # lGetOptionsArgs adds sMt4Dir/MQL4/Python to the sys.path
    (oOptions, lArgs,) = lGetOptionsArgs()
    # so lGetOptionsArgs must be called before this import
    from ZmqBinListener import ZmqBinMixin

    if not lArgs:
        # subscribe to everything
        lArgs = ['']
    lTopics = lArgs

    oMixin = None
    try:
        # sChartId is in oOptions
        oMixin = ZmqBinMixin(**oOptions.__dict__)
        oMixin.eConnectToSubPub(lTopics, iDir=zmq.SUB)
        oMixin.eConnectToReqRep(iDir=zmq.REQ)

        i = 0
        while True:

            i += 1
            sys.stderr.write("Command: ")
            sRequest = sys.stdin.readline().strip()
            if not sRequest: break

            if oOptions.sExecType == "default":
                sType = sDefaultExecType(sRequest)
            elif oOptions.sExecType == "exec":
                # execs are executed immediately and return a result on the wire
                # They're things that take less than a tick to evaluate
                sType = "exec"
            else:
                sType = "cmd"
            # only exec really works right now - cmd misses the retval sometimes
            sType = "exec"

            sMarkIn = sMakeMark()
            gRetval = oMixin.gCmdExec(sMarkIn, sRequest, sType, oOptions)
            print gRetval

    except KeyboardInterrupt:
       if oOptions and oOptions.iDebugLevel >= 1:
           vInfo("exiting")

    except Exception as e:
        vError(str(e) +"\n" + \
               traceback.format_exc(10) +"\n")
        sys.stdout.flush()
        sys.exc_clear()

    finally:
       if oMixin:
           oMixin.bCloseContextSockets()

    return 0
示例#5
0
    def eSendOnSpeaker(self, sType, sMess):
        if sType not in lKNOWN_TOPICS:
            sRetval = "eSendOnSpeaker: oSpeakerChannel unhandled topic " +sMess
            vError(sRetval)
            return sRetval
        if self.oSpeakerChannel is None:
            self.eBindBlockingSpeaker()

        assert self.oSpeakerChannel, "eSendOnSpeaker: oSpeakerChannel is null"
        assert self.oConnection, "eSendOnSpeaker: oConnection is null"

        # we will break the sChartId up into dots from the underscores
        # That way the end consumer can look at the feed selectively
        sPublishingKey = sType + '.' + self.sChartId.replace('_', '.')

        self.oSpeakerChannel.basic_publish(exchange=self.sExchangeName,
                                           routing_key=sPublishingKey,
                                           body=sMess,
                                           mandatory=False, immediate=False,
                                           properties=self.oProperties)
        vDebug("eSendOnSpeaker: sent " + sMess)
        return ""
示例#6
0
    def eSendOnSpeaker(self, sType, sMess):
        if sType not in lKNOWN_TOPICS:
            sRetval = "eSendOnSpeaker: oSpeakerChannel unhandled topic " + sMess
            vError(sRetval)
            return sRetval
        if self.oSpeakerChannel is None:
            self.eBindBlockingSpeaker()

        assert self.oSpeakerChannel, "eSendOnSpeaker: oSpeakerChannel is null"
        assert self.oConnection, "eSendOnSpeaker: oConnection is null"

        # we will break the sChartId up into dots from the underscores
        # That way the end consumer can look at the feed selectively
        sPublishingKey = sType + '.' + self.sChartId.replace('_', '.')

        self.oSpeakerChannel.basic_publish(exchange=self.sExchangeName,
                                           routing_key=sPublishingKey,
                                           body=sMess,
                                           mandatory=False,
                                           immediate=False,
                                           properties=self.oProperties)
        vDebug("eSendOnSpeaker: sent " + sMess)
        return ""
示例#7
0
    def zPopFromPending(self, sString):
        from OTMql427.SimpleFormat import gRetvalToPython
        global dPENDING

        lElts = sString.split('|')
        if len(lElts) <= 4:
            vWarn("not enough | found in: %s" % (sString,))
            return ""

        if sString.startswith('tick') or sString.startswith('timer'):
            print sString
            return ""

        if sString.startswith('retval'):
            sMarkOut = lElts[3]
            if sMarkOut not in dPENDING.keys():
                print "WARN: %s not found in: %r" % (sMarkOut, dPENDING.keys())
            else:
                del dPENDING[sMarkOut]
            sType = lElts[4]
            sVal = lElts[5]

            print "INFO: " +sMarkOut +" "+ sString
            if sType == "cmd":
                # there's still a null that comes back on ReqRep
                sNull = self.oReqRepSocket.recv()
                # zmq.error.ZMQError
            try:
                gRetval = gRetvalToPython(lElts)
            except Exception as e:
                vError("zPopFromPending: error in gRetvalToPython " +sString +str(e))
            else:
                return gRetval
        else:
            vWarn("Unrecognized message: " + sString)
        return ""