def attachAndSpawnDaemons(self, session, hostname, pid, daemon, d_argv, febe_data, befe_data): """Invoke LMON_fe_attachAndSpawnDaemons. See the manpages. d_argv is a list. befe_data is the size of the desired buffer or None. """ # Need a trailing null entry on the array. d_argv += [None] _d_argv = lmon.create_array(c_char_p, d_argv) if febe_data is not None: _febe_data = lmon.udata_serialize(febe_data) else: _febe_data = cast(None, c_void_p) buf = None if befe_data is not None: buf = create_string_buffer(befe_data) _befe_data = cast(buf, c_void_p) else: _befe_data = cast(None, c_void_p) lmon.call(self.lib.LMON_fe_attachAndSpawnDaemons, session, hostname, pid, daemon, _d_argv, _febe_data, _befe_data) if befe_data: return lmon.udata_unserialize(buf.value) else: return None
def recvUsrData(self, buf_size): """Receive data from the front-end.""" udata = create_string_buffer(buf_size) lmon.call(self.lib.LMON_be_recvUsrData, cast(udata, c_void_p)) if self.amIMaster(): return lmon.udata_unserialize(udata.raw) return None
def handshake(self, udata): """Do the LaunchMON handshake. If udata is not None, it should be the length of the buffer to unserialize front-end data to. """ if udata is None: lmon.call(self.lib.LMON_be_handshake, cast(None, c_void_p)) else: buf = create_string_buffer(udata) lmon.call(self.lib.LMON_be_handshake, cast(buf, c_void_p)) # Check if we actually received data. if buf.raw[0] != "\0": return lmon.udata_unserialize(buf.value) return None
def scatter(self, udata_array, elem_size): """Scatter data. The master provides udata_array, which is an array of data to scatter. The slaves may provide None for the data. elem_size is the size of each element. Due to serialization of data, this should be the maximum size of the data, and the elements are padded to this length. All callers return their respective data (including the master). """ buf = create_string_buffer(elem_size) if self.amIMaster(): # Master pads data if needed and sends. total_size = len(udata_array) * elem_size send_buf = create_string_buffer(total_size) buf_addr = addressof(send_buf) idx = 0 for elem in udata_array: tmp_buf = create_string_buffer( string_at(lmon.udata_serialize(elem)), elem_size) memmove(buf_addr + (idx * elem_size), tmp_buf, elem_size) idx += 1 lmon.call(self.lib.LMON_be_scatter, cast(send_buf, c_void_p), elem_size, cast(buf, c_void_p)) else: lmon.call(self.lib.LMON_be_scatter, cast(None, c_void_p), elem_size, cast(buf, c_void_p)) # This is here for the same reason as in broadcast. # Note that it appears that the null byte is only present for children. if buf.raw[0] == "\0" and buf.raw[1] != "\0": buf = string_at(addressof(buf) + 1) else: buf = buf.value return lmon.udata_unserialize(buf)
def broadcast(self, udata, size): """Broadcast data. The master provides data and the size of it, and this returns None. The slaves can provide None for the data, and size is the size of the buffer, which is returned after unserialization. """ if self.amIMaster(): # Master sends the data, returns None. lmon.call(self.lib.LMON_be_broadcast, lmon.udata_serialize(udata), size) return None else: # Slave returns the data. buf = create_string_buffer(size) lmon.call(self.lib.LMON_be_broadcast, cast(buf, c_void_p), size) # Depending on the application, there appears to be a spurious null # byte at the start of the data. I do not know why. This avoids it. if buf.raw[0] == "\0" and buf.raw[1] != "\0": buf = string_at(addressof(buf) + 1) else: buf = buf.value return lmon.udata_unserialize(buf)
def launchAndSpawnDaemons(self, session, hostname, launcher, l_argv, daemon, d_argv, febe_data, befe_data): """Invoke LMON_fe_launchAndSpawnDaemons.""" # Need trailing null entries on the arrays. l_argv += [None] d_argv += [None] _l_argv = lmon.create_array(c_char_p, l_argv) _d_argv = lmon.create_array(c_char_p, d_argv) if febe_data is not None: _febe_data = lmon.udata_serialize(febe_data) else: _febe_data = cast(None, c_void_p) buf = None if befe_data is not None: buf = create_string_buffer(befe_data) _befe_data = cast(buf, c_void_p) else: _befe_data = cast(None, c_void_p) lmon.call(self.lib.LMON_fe_launchAndSpawnDaemons, session, hostname, launcher, _l_argv, daemon, _d_argv, _febe_data, _befe_data) if befe_data: return lmon.udata_unserialize(buf.value) else: return None
def recvUsrDataBe(self, session, buf_size): """Receive user data from the backend with LMON_fe_recvUsrDataBe (it is unserialized).""" befe_data = create_string_buffer(buf_size) lmon.call(self.lib.LMON_fe_recvUsrDataBe, session, cast(befe_data, c_void_p)) return lmon.udata_unserialize(befe_data.raw)
def recvUsrDataBe(self, session, buf_size): """Receive user data from the backend.""" befe_data = create_string_buffer(buf_size) lmon.call(self.lib.LMON_fe_recvUsrDataBe, session, cast(befe_data, c_void_p)) return lmon.udata_unserialize(befe_data.raw)