endurox.tpsetunsol

endurox.tpsetunsol(func: object) None

Set unsolicited message callback handler. Handler receives matched messages posted by tpnotify() and tpbroadcast(). Note that in handler only limited ATMI processing may be done. See C API descr. Note that callback handler is associated with the ATMI context. If using several contexts or threads, each of them shall be initialized.

For more details see tpsetunsol(3) C API call.

tpsetunsol example
import unittest
import endurox as e

class TestTpnotify(unittest.TestCase):

    cnt = 0

    def unsol_handler(self, data):
        if data["data"] == "HELLO WORLD":
            TestTpnotify.cnt=TestTpnotify.cnt+1

    # NOTIFSV publishes one notification to this CLIENTID.
    def test_tpnotify(self):
        e.tpsetunsol(self.unsol_handler)
        tperrno, tpurcode, retbuf = e.tpcall("NOTIFSV", { "data":{"T_STRING_FLD":"Hi Jim"}})
        self.assertEqual(1, TestTpnotify.cnt)
        e.tpterm()

if __name__ == '__main__':
    unittest.main()
Raises:

AtmiException

Following error codes may be present:
TPEINVAL - Invalid environment or invalid parameters.
TPESYSTEM - System error occurred.
TPEOS - Operating system error occurred.

Parameters:

func (callbackFunction(data) -> None) – Callback function to be invoked when unsolicited message is received by the process. data parameter is standard ATMI buffer.