@_glib_err_wrap
	def _rpc_call(self, buff, stream=None, ev=None):
		assert stream is self.stdin, [stream, self.stdin]

		if ev is None: ev = self._glib.IO_IN
		if ev & (self._glib.IO_ERR | self._glib.IO_HUP):
			return self.loop.quit() # parent is gone, we're done too
		elif ev & self._glib.IO_IN:
			while True:
				try: chunk = self.stdin.read(2**20)
				except __HOLE__ as err:
					if err.errno != errno.EAGAIN: raise
					chunk = None
				if not chunk: break
				buff.append(chunk)
			while True:
				# Detect if there are any full requests buffered
				for n, chunk in enumerate(buff):
					if '\n' in chunk: break
				else: break # no more full requests

				# Read/decode next request from buffer
				req = list()
				for m in xrange(n+1):
					chunk = buff.popleft()
					if m == n:
						chunk, chunk_next = chunk.split('\n', 1)
						buff.appendleft(chunk_next)
					assert '\n' not in chunk, chunk
					req.append(chunk)
				req = json.loads(''.join(req))
				self.line_debug.append(('rpc-child(py) << %s', req))
				if self.log_pipes: log.debug(*self.line_debug[-1])

				# Run dbus call and return the result, synchronously
				assert req['t'] == 'call', req
				func, kws = req['func'], dict()
				obj_path, iface = req.get('obj'), req.get('iface')
				args, translate = req['args'], req.get('translate')
				if iface: kws['dbus_interface'] = dbus_abbrev(iface)
				if translate: args = self._dbus_val(args, translate)
				obj = self.core if not obj_path\
					else self.bus.get_object(object_path=obj_path) # XXX: bus gone handling
				log.debug('DBus call: %s %s %s', func, args, kws)
				try: res = getattr(obj, func)(*args, **kws)
				except self._dbus.exceptions.DBusException as err:
					self._core_notify( t='call_error', cid=req['cid'],
						err_type=err.get_dbus_name(), err_msg=err.message )
				else:
					res = strip_dbus_types(res)
					self._core_notify(t='call_result', cid=req['cid'], val=res)
		else:
			log.warn('Unrecognized event type from glib: %r', ev)
dataset/ETHPy150Open mk-fg/pulseaudio-mixer-cli/pa-mixer-mk2.py/PAMixerDBusBridge._rpc_call