Example #1
0
 def __init__(
     self,
     flux_handle,
     type_mask,
     callback,
     topic_glob="*",
     match_tag=flux.constants.FLUX_MATCHTAG_NONE,
     args=None,
 ):
     self.flux_handle = flux_handle
     self.callback = callback
     self.args = args
     self.wargs = ffi.new_handle(self)
     c_topic_glob = ffi.new("char[]", topic_glob)
     match = ffi.new(
         "struct flux_match *",
         {
             "typemask": type_mask,
             "matchtag": match_tag,
             "topic_glob": c_topic_glob
         },
     )
     super(MessageWatcher, self).__init__(
         raw.flux_msg_handler_create(self.flux_handle.handle, match[0],
                                     message_handler_wrapper, self.wargs))
Example #2
0
    def __init__(
        self,
        flux_handle,
        type_mask,
        callback,
        topic_glob="*",
        match_tag=flux.constants.FLUX_MATCHTAG_NONE,
        args=None,
    ):
        self.callback = callback
        self.args = args
        self.wargs = ffi.new_handle(self)

        if topic_glob is None or topic_glob == ffi.NULL:
            topic_glob = ffi.NULL
        elif isinstance(topic_glob, str):
            topic_glob = topic_glob.encode("UTF-8")
        elif not isinstance(topic_glob, bytes):
            errmsg = "Topic must be a string, not {}".format(type(topic_glob))
            raise TypeError(errno.EINVAL, errmsg)
        c_topic_glob = ffi.new("char[]", topic_glob)

        match = ffi.new(
            "struct flux_match *",
            {"typemask": type_mask, "matchtag": match_tag, "topic_glob": c_topic_glob},
        )
        super(MessageWatcher, self).__init__(
            flux_handle,
            raw.flux_msg_handler_create(
                flux_handle.handle,
                match[0],
                lib.message_handler_wrapper,
                self.wargs,
            ),
        )
Example #3
0
    def __init__(
        self,
        flux_handle,
        type_mask,
        callback,
        topic_glob="*",
        match_tag=flux.constants.FLUX_MATCHTAG_NONE,
        args=None,
    ):
        self.flux_handle = flux_handle
        self.callback = callback
        self.args = args
        self.wargs = ffi.new_handle(self)

        if topic_glob is None or topic_glob == ffi.NULL:
            topic_glob = ffi.NULL
        elif isinstance(topic_glob, six.text_type):
            topic_glob = topic_glob.encode("UTF-8")
        elif not isinstance(topic_glob, six.binary_type):
            errmsg = "Topic must be a string, not {}".format(type(topic_glob))
            raise TypeError(errno.EINVAL, errmsg)
        c_topic_glob = ffi.new("char[]", topic_glob)

        match = ffi.new(
            "struct flux_match *",
            {"typemask": type_mask, "matchtag": match_tag, "topic_glob": c_topic_glob},
        )
        super(MessageWatcher, self).__init__(
            raw.flux_msg_handler_create(
                self.flux_handle.handle, match[0], message_handler_wrapper, self.wargs
            )
        )
Example #4
0
 def get_str(self):
     # pylint: disable=duplicate-code
     resp_str = ffi.new("char *[1]")
     self.pimpl.get(resp_str)
     if resp_str[0] == ffi.NULL:
         return None
     return ffi.string(resp_str[0]).decode("utf-8")
Example #5
0
 def get_str(self):
     # pylint: disable=duplicate-code
     resp_str = ffi.new("char *[1]")
     self.pimpl.get(resp_str)
     if resp_str[0] == ffi.NULL:
         return None
     return ffi.string(resp_str[0]).decode("utf-8")
Example #6
0
 def payload_str(self):
     s = ffi.new('char *[1]')
     if self.pimpl.has_payload():
         self.pimpl.get_json(ffi.cast('char**', s))
         return ffi.string(s[0])
     else:
         return None
Example #7
0
 def payload_str(self):
     s = ffi.new('char *[1]')
     if self.pimpl.has_payload():
         self.pimpl.get_payload_json(ffi.cast('char**', s))
         return ffi.string(s[0])
     else:
         return None
Example #8
0
 def __init__(self, flux_handle, type_mask, callback,
              topic_glob='*',
              match_tag=flux.FLUX_MATCHTAG_NONE,
              args=None):
     self.handle = None
     self.fh = flux_handle
     self.cb = callback
     self.args = args
     self.wargs = ffi.new_handle(self)
     c_topic_glob = ffi.new('char[]', topic_glob)
     match = ffi.new('struct flux_match *', {
         'typemask': type_mask,
         'matchtag': match_tag,
         'topic_glob': c_topic_glob,
     })
     self.handle = raw.flux_msg_handler_create(self.fh.handle, match[0],
                                               message_handler_wrapper,
                                               self.wargs)
Example #9
0
 def __init__(self, flux_handle, type_mask, callback,
              topic_glob='*',
              match_tag=flux.FLUX_MATCHTAG_NONE,
              bsize=0,
              args=None):
     self.handle = None
     self.fh = flux_handle
     self.cb = callback
     self.args = args
     wargs = ffi.new_handle(self)
     c_topic_glob = ffi.new('char[]', topic_glob)
     match = ffi.new('struct flux_match *', {
         'typemask': type_mask,
         'matchtag': match_tag,
         'bsize': bsize,
         'topic_glob': c_topic_glob,
     })
     self.handle = raw.flux_msg_watcher_create(match[0],
                                               message_handler_wrapper,
                                               wargs)
Example #10
0
 def __init__(self, flux_handle, type_mask, callback,
              topic_glob='*',
              match_tag=flux.constants.FLUX_MATCHTAG_NONE,
              args=None):
     self.flux_handle = flux_handle
     self.callback = callback
     self.args = args
     self.wargs = ffi.new_handle(self)
     c_topic_glob = ffi.new('char[]', topic_glob)
     match = ffi.new('struct flux_match *', {
         'typemask': type_mask,
         'matchtag': match_tag,
         'topic_glob': c_topic_glob,
     })
     super(MessageWatcher, self).__init__(
         raw.flux_msg_handler_create(
             self.flux_handle.handle,
             match[0],
             message_handler_wrapper,
             self.wargs))
Example #11
0
def strtostate(args):
    state = ffi.new("flux_job_state_t [1]")
    if not args.strings:
        args.strings = [line.strip() for line in sys.stdin]

    for s in args.strings:
        try:
            raw.flux_job_strtostate(s, state)
        except Exception:
            print(f"invalid string {s}")
            sys.exit(1)
        print(int(state[0]))
Example #12
0
def strtoresult(args):
    result = ffi.new("flux_job_result_t [1]")
    if not args.strings:
        args.strings = [line.strip() for line in sys.stdin]

    for s in args.strings:
        try:
            raw.flux_job_strtoresult(s, result)
        except Exception:
            print(f"invalid string {s}")
            sys.exit(1)
        print(int(result[0]))
Example #13
0
 def topic(self):
     s = ffi.new('char *[1]')
     self.pimpl.get_topic(s)
     return ffi.string(s[0])
Example #14
0
 def get_str(self):
     payload_str = ffi.new("char *[1]")
     self.pimpl.flux_rpc_get(payload_str)
     if payload_str[0] == ffi.NULL:
         return None
     return ffi.string(payload_str[0]).decode("utf-8")
Example #15
0
 def payload_str(self):
     string = ffi.new("char *[1]")
     if self.pimpl.has_payload():
         self.pimpl.get_string(ffi.cast("char**", string))
         return ffi.string(string[0]).decode("utf-8")
     return None
Example #16
0
 def topic(self):
     topic_string = ffi.new("char *[1]")
     self.pimpl.get_topic(topic_string)
     return ffi.string(topic_string[0]).decode("utf-8")
Example #17
0
 def get_nodeid(self):
     nodeid = ffi.new("uint32_t [1]")
     self.pimpl.get_nodeid(nodeid)
     return int(nodeid[0])
Example #18
0
 def type(self):
     message_type = ffi.new("int [1]")
     self.pimpl.get_type(message_type)
     return message_type[0]
Example #19
0
 def get_nodeid(self):
     nodeid = ffi.new("uint32_t [1]")
     self.pimpl.get_nodeid(nodeid)
     return int(nodeid[0])
Example #20
0
 def get_str(self):
     j_str = ffi.new('char *[1]')
     self.pimpl.get(j_str)
     return ffi.string(j_str[0])
Example #21
0
 def topic(self):
     topic_string = ffi.new('char *[1]')
     self.pimpl.get_topic(topic_string)
     return ffi.string(topic_string[0])
Example #22
0
 def payload_str(self):
     string = ffi.new("char *[1]")
     if self.pimpl.has_payload():
         self.pimpl.get_string(ffi.cast("char**", string))
         return ffi.string(string[0]).decode("utf-8")
     return None
Example #23
0
 def get_str(self):
     j_str = ffi.new("char *[1]")
     self.pimpl.get(j_str)
     if j_str[0] == ffi.NULL:
         return None
     return ffi.string(j_str[0]).decode("utf-8")
Example #24
0
 def topic(self):
     s = ffi.new('char *[1]')
     self.pimpl.get_topic(s)
     return ffi.string(s[0])
Example #25
0
 def get_str(self):
     payload_str = ffi.new("char *[1]")
     self.pimpl.flux_rpc_get(payload_str)
     if payload_str[0] == ffi.NULL:
         return None
     return ffi.string(payload_str[0]).decode("utf-8")
Example #26
0
 def type(self):
     s = ffi.new('int [1]')
     self.pimpl.get_type(s)
     return s[0]
Example #27
0
 def get_str(self):
     j_str = ffi.new("char *[1]")
     self.pimpl.get(j_str)
     if j_str[0] == ffi.NULL:
         return None
     return ffi.string(j_str[0]).decode("utf-8")
Example #28
0
 def topic(self):
     topic_string = ffi.new("char *[1]")
     self.pimpl.get_topic(topic_string)
     return ffi.string(topic_string[0]).decode("utf-8")
Example #29
0
 def type(self):
     s = ffi.new('int [1]')
     self.pimpl.get_type(s)
     return s[0]
Example #30
0
 def type(self):
     message_type = ffi.new("int [1]")
     self.pimpl.get_type(message_type)
     return message_type[0]
Example #31
0
 def get_str(self):
     j_str = ffi.new('char *[1]')
     self.pimpl.get(j_str)
     return ffi.string(j_str[0])