samples: delete GUI samples
The progress of GUI toolkit development is so fast, while I would like to
keep the integration of libhinawa so small.
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
diff --git a/README.rst b/README.rst
index f26a01c..cee40d9 100644
--- a/README.rst
+++ b/README.rst
@@ -99,9 +99,6 @@
Some sample scripts are available under ``samples`` directory:
-- gtk3 - PyGObject is required.
-- gtk4 - PyGObject is required.
-- qt5 - PyQt5 is required.
- read-quadlet - demonstration to read quadlet data from node in IEEE 1394 bus
- read-quadlet-async - demonstration of the above example with asynchronous runtime
diff --git a/samples/common/__init__.py b/samples/common/__init__.py
index 75c46f1..9fd61ca 100644
--- a/samples/common/__init__.py
+++ b/samples/common/__init__.py
@@ -1,14 +1,6 @@
from sys import stderr
from pathlib import Path
from struct import unpack
-from contextlib import contextmanager
-from threading import Thread
-
-import gi
-gi.require_versions({'GLib': '2.0', 'Hinawa': '4.0'})
-from gi.repository import GLib, Hinawa
-
-CLOCK_MONOTONIC_RAW = 4
def print_help_with_msg(cmd: str, msg: str):
@@ -59,216 +51,3 @@
print(" sent at: {} sec {} cycle".format(sent_cycle[0], sent_cycle[1]))
print(" received at: {} sec {} cycle".format(recv_cycle[0], recv_cycle[1]))
print(" finish at: {} sec {} cycle".format(finish_cycle[0], finish_cycle[1]))
-
-
-def print_generation_information(node: Hinawa.FwNode):
- print(' Topology:')
- print(' self: {:04x}'.format(node.get_property('node-id')))
- print(' local: {:04x}'.format(node.get_property('local-node-id')))
- print(' root: {:04x}'.format(node.get_property('root-node-id')))
- print(' bus-manager: {:04x}'.format(node.get_property('bus-manager-node-id')))
- print(' ir-manager: {:04x}'.format(node.get_property('ir-manager-node-id')))
- print(' generation: {}'.format(node.get_property('generation')))
-
-
-def print_fw_node_information(node: Hinawa.FwNode):
- print('IEEE1394 node info:')
-
- print_generation_information(node)
-
- print(' Config ROM:')
- _, image = node.get_config_rom()
- quads = unpack('>{}I'.format(len(image) // 4), image)
- for i, q in enumerate(quads):
- print(' 0xfffff00004{:02x}: 0x{:08x}'.format(i * 4, q))
-
-
-def read_quadlet(node: Hinawa.FwNode, req: Hinawa.FwReq, addr: int) -> int:
- cycle_time = Hinawa.CycleTime.new()
-
- try:
- _, cycle_time = node.read_cycle_time(CLOCK_MONOTONIC_RAW, cycle_time)
- except Exception as e:
- print(e)
- return 0
- initiate_cycle = cycle_time.get_fields()[:2]
-
- frame = [0] * 4
- try:
- _, frame, tstamp = req.transaction_with_tstamp(
- node,
- Hinawa.FwTcode.READ_QUADLET_REQUEST,
- addr,
- len(frame),
- frame,
- 100
- )
- except Exception as e:
- print(e)
-
- sent_cycle = cycle_time.compute_tstamp(tstamp[0])
- recv_cycle = cycle_time.compute_tstamp(tstamp[1])
-
- try:
- _, cycle_time = node.read_cycle_time(CLOCK_MONOTONIC_RAW, cycle_time)
- except Exception as e:
- print(e)
- return 0
- finish_cycle = cycle_time.get_fields()[:2]
-
- quadlet = unpack('>I', frame)[0]
-
- print('Read quadlet transaction:')
- print(' addr 0x{:012x}, quadlet: 0x{:08x}'.format(addr, quadlet))
- print(' initiate at: sec {} cycle {}'.format(initiate_cycle[0], initiate_cycle[1]))
- print(' sent at: sec {} cycle {}'.format(sent_cycle[0], sent_cycle[1]))
- print(' received at: sec {} cycle {}'.format(recv_cycle[0], recv_cycle[1]))
- print(' finish at: sec {} cycle {}'.format(finish_cycle[0], finish_cycle[1]))
-
- return quadlet
-
-
-@contextmanager
-def run_dispatcher(node: Hinawa.FwNode):
- ctx = GLib.MainContext.new()
- _, src = node.create_source()
- src.attach(ctx)
-
- dispatcher = GLib.MainLoop.new(ctx, False)
- th = Thread(target=lambda d: d.run(), args=(dispatcher,))
- th.start()
-
- yield
-
- dispatcher.quit()
- th.join()
-
-
-def handle_bus_update(node: Hinawa.FwNode):
- print('Event: bus-update:')
- print_generation_information(node)
-
-
-@contextmanager
-def listen_bus_update(node: Hinawa.FwNode):
- handler = node.connect('bus-update', handle_bus_update)
- yield
- node.disconnect(handler)
-
-
-def print_frame(frame: list):
- for i in range(len(frame)):
- print(' [{:02d}]: 0x{:02x}'.format(i, frame[i]))
-
-
-def handle_requested(resp: Hinawa.FwResp, tcode: Hinawa.FwRcode, offset: int,
- src: int, dst: int, card: int, generation: int, tstamp: int,
- frame: list, length: int, args: tuple[Hinawa.FwNode, Hinawa.CycleTime]):
- node, cycle_time = args
- print('Event requested: {0}'.format(tcode.value_nick))
- try:
- _, cycle_time = node.read_cycle_time(CLOCK_MONOTONIC_RAW, cycle_time)
- isoc_cycle = cycle_time.compute_tstamp(tstamp)
- except Exception as e:
- print(e)
- isoc_cycle = [0] * 2
- pass
- print_frame(frame)
- print(' received at: sec {0[0]} cycle {0[1]}'.format(isoc_cycle))
- return Hinawa.FwRcode.COMPLETE
-
-
-@contextmanager
-def listen_region(node: Hinawa.FwNode):
- resp = Hinawa.FwResp()
- cycle_time = Hinawa.CycleTime.new()
- handler = resp.connect('requested', handle_requested, (node, cycle_time))
- try:
- _ = resp.reserve(node, 0xfffff0000d00, 0x100)
- yield
- except Exception as e:
- print(e)
-
- resp.disconnect(handler)
- resp.release()
-
-
-def handle_responded(fcp: Hinawa.FwFcp, generation: int, tstamp: int, frame: list,
- length: int, args: tuple[Hinawa.FwNode, Hinawa.CycleTime]):
- node, cycle_time = args
- print('Event responded: length {}'.format(length))
- try:
- _, cycle_time = node.read_cycle_time(CLOCK_MONOTONIC_RAW, cycle_time)
- isoc_cycle = cycle_time.compute_tstamp(tstamp)
- except Exception as e:
- print(e)
- isoc_cycle = [0] * 2
- pass
- print_frame(frame)
- print(' received at: sec {0[0]} cycle {0[1]}'.format(isoc_cycle))
-
-
-@contextmanager
-def listen_fcp(node: Hinawa.FwNode):
- cycle_time = Hinawa.CycleTime.new()
-
- fcp = Hinawa.FwFcp()
- handler = fcp.connect('responded', handle_responded, (node, cycle_time))
- try:
- _ = fcp.bind(node)
-
- _, cycle_time = node.read_cycle_time(CLOCK_MONOTONIC_RAW, cycle_time)
- initiate_cycle = cycle_time.get_fields()[:2]
-
- request = bytes([0x01, 0xff, 0x19, 0x00, 0xff, 0xff, 0xff, 0xff])
- _, response, tstamp = fcp.avc_transaction_with_tstamp(request, [0] * len(request), 100)
-
- req_sent_cycle = cycle_time.compute_tstamp(tstamp[0])
- req_responded_cycle = cycle_time.compute_tstamp(tstamp[1])
- resp_sent_cycle = cycle_time.compute_tstamp(tstamp[2])
-
- _, cycle_time = node.read_cycle_time(CLOCK_MONOTONIC_RAW, cycle_time)
- finish_cycle = cycle_time.get_fields()[:2]
-
- print('FCP request:')
- print_frame(request)
- print(' initiate at: sec {0[0]} cycle {0[1]}'.format(initiate_cycle))
- print(' sent at: sec {0[0]} cycle {0[1]}'.format(req_sent_cycle))
- print(' received at: sec {0[0]} cycle {0[1]}'.format(req_responded_cycle))
-
- print('FCP response:')
- print_frame(response)
- print(' received at: sec {0[0]} cycle {0[1]}'.format(resp_sent_cycle))
- print(' finished at: sec {0[0]} cycle {0[1]}'.format(finish_cycle))
-
- yield
- except Exception as e:
- print(e)
-
- fcp.disconnect(handler)
- fcp.unbind()
-
-
-@contextmanager
-def listen_node_event(node: Hinawa.FwNode, path: Path):
- root = Path.cwd().parents[-1]
- sysfs_path = root.joinpath('sys', 'bus', 'firewire', 'devices', path.name, 'units')
-
- # Linux FireWire subsystem exports all of pairs of specifier_id and version in unit directory
- # via sysfs, thus not need to parse the content of configuration ROM.
- with sysfs_path.open('r') as f:
- content = f.read()
-
- # The specifier_id for 1394TA is expected to express the device implements FCP.
- has_fcp = content.find('0x00a02d') >= 0
-
- if has_fcp:
- with run_dispatcher(node), listen_bus_update(node), listen_region(node), listen_fcp(node):
- yield
- else:
- with run_dispatcher(node), listen_bus_update(node):
- yield
-
-
-__all__ = ['print_help_with_msg', 'detect_fw_cdev', 'run_async_transaction',
- 'dump_fw_node_information', 'listen_node_event']
diff --git a/samples/gtk3 b/samples/gtk3
deleted file mode 100755
index 45d9539..0000000
--- a/samples/gtk3
+++ /dev/null
@@ -1,91 +0,0 @@
-#!/usr/bin/env python3
-
-from pathlib import Path
-from sys import argv, exit
-from signal import SIGINT
-from struct import unpack
-import common
-
-import gi
-gi.require_versions({'GLib': '2.0', 'Hinawa': '4.0', 'Gtk': '3.0'})
-from gi.repository import GLib, Hinawa, Gtk
-
-
-def main() -> int:
- if len(argv) < 2:
- msg = ('One argument is required for path to special file of Linux FireWire character '
- 'device')
- common.print_help_with_msg(Path(__file__).name, msg)
- return 1
- cmd, literal = argv[:2]
-
- try:
- path = common.detect_fw_cdev(literal)
- except Exception as e:
- common.print_help_with_msg(cmd, str(e))
- return 1
-
- try:
- node = Hinawa.FwNode.new()
- _ = node.open(str(path), 0)
- common.print_fw_node_information(node)
- except Exception as e:
- msg = str(e)
- common.print_help_with_msg(cmd, msg)
- return 1
-
- with common.listen_node_event(node, path):
- sample = Sample(node)
- sample.show_all()
- node.connect('disconnected', lambda n, s: Gtk.main_quit(), sample)
- Gtk.main()
-
- return 0
-
-
-class Sample(Gtk.Window):
- def __init__(self, node):
- Gtk.Window.__init__(self, title="Hinawa-4.0 gir sample")
-
- self.node = node
- self.req = Hinawa.FwReq.new()
-
- grid = Gtk.Grid(row_spacing=10, row_homogeneous=True,
- column_spacing=10, column_homogeneous=True,
- margin_start=20, margin_end=20, margin_top=20,
- margin_bottom=20)
- self.add(grid)
-
- button = Gtk.Button(label="Read")
- button.connect("clicked", self.run_transaction)
- grid.attach(button, 0, 0, 1, 1)
-
- button = Gtk.Button(label="_Close", use_underline=True)
- button.connect("clicked", lambda s: Gtk.main_quit())
- grid.attach(button, 1, 0, 1, 1)
-
- self.entry = Gtk.Entry()
- self.entry.set_text("0xfffff0000980")
- grid.attach(self.entry, 0, 1, 1, 1)
-
- self.label = Gtk.Label(label="result")
- self.label.set_text("0x00000000")
- grid.attach(self.label, 1, 1, 1, 1)
-
- # handle unix signal
- GLib.unix_signal_add(GLib.PRIORITY_HIGH, SIGINT, lambda s: Gtk.main_quit(), self)
-
- def run_transaction(self, button):
- addr = int(self.entry.get_text(), 16)
- frames = [0] * 4
- try:
- quadlet = common.read_quadlet(self.node, self.req, addr)
- except Exception as e:
- print(e)
-
- label = '0x{:08x}'.format(quadlet)
- self.label.set_text(label)
-
-
-if __name__ == '__main__':
- exit(main())
diff --git a/samples/gtk4 b/samples/gtk4
deleted file mode 100755
index 4c4630b..0000000
--- a/samples/gtk4
+++ /dev/null
@@ -1,95 +0,0 @@
-#!/usr/bin/env python3
-
-from pathlib import Path
-from sys import argv, exit
-from signal import SIGINT
-from struct import unpack
-import common
-
-import gi
-gi.require_versions({'GLib': '2.0', 'Hinawa': '4.0', 'Gtk': '4.0'})
-from gi.repository import GLib, Hinawa, Gtk
-
-
-def main() -> int:
- if len(argv) < 2:
- msg = ('One argument is required for path to special file of Linux FireWire character '
- 'device')
- common.print_help_with_msg(Path(__file__).name, msg)
- return 1
- cmd, literal = argv[:2]
-
- try:
- path = common.detect_fw_cdev(literal)
- except Exception as e:
- common.print_help_with_msg(cmd, str(e))
- return 1
-
- try:
- node = Hinawa.FwNode.new()
- _ = node.open(str(path), 0)
- common.print_fw_node_information(node)
- except Exception as e:
- msg = str(e)
- common.print_help_with_msg(cmd, msg)
- return 1
-
- with common.listen_node_event(node, path):
- main_dispatcher = GLib.MainLoop.new(None, False)
- node.connect('disconnected', lambda n, d: d.quit(), main_dispatcher)
-
- win = Sample(main_dispatcher, node)
- win.present()
-
- main_dispatcher.run()
-
- return 0
-
-
-class Sample(Gtk.Window):
- def __init__(self, dispatcher, node):
- Gtk.Window.__init__(self, title="Hinawa-4.0 gir sample")
-
- self.node = node
- self.req = Hinawa.FwReq.new()
-
- grid = Gtk.Grid(row_spacing=10, row_homogeneous=True,
- column_spacing=10, column_homogeneous=True,
- margin_start=20, margin_end=20, margin_top=20,
- margin_bottom=20)
- self.set_child(grid)
-
- button = Gtk.Button(label="Read")
- button.connect("clicked", self.run_transaction)
- grid.attach(button, 0, 0, 1, 1)
-
- button = Gtk.Button(label="_Close", use_underline=True)
- button.connect("clicked", lambda s, d: d.quit(), dispatcher)
- grid.attach(button, 1, 0, 1, 1)
-
- self.entry = Gtk.Entry()
- self.entry.set_text("0xfffff0000980")
- grid.attach(self.entry, 0, 1, 1, 1)
-
- self.label = Gtk.Label(label="result")
- self.label.set_text("0x00000000")
- grid.attach(self.label, 1, 1, 1, 1)
-
- # handle unix signal
- GLib.unix_signal_add(GLib.PRIORITY_HIGH, SIGINT, lambda d: d.quit(), dispatcher)
-
- def run_transaction(self, button):
- addr = int(self.entry.get_text(), 16)
- frame = [0] * 4
-
- try:
- quadlet = common.read_quadlet(self.node, self.req, addr)
- except Exception as e:
- print(e)
-
- label = '0x{:08x}'.format(quadlet)
- self.label.set_text(label)
-
-
-if __name__ == '__main__':
- exit(main())
diff --git a/samples/qt5 b/samples/qt5
deleted file mode 100755
index 62bc9bd..0000000
--- a/samples/qt5
+++ /dev/null
@@ -1,116 +0,0 @@
-#!/usr/bin/env python3
-
-from pathlib import Path
-from sys import argv, exit
-from signal import SIGINT
-from struct import unpack
-import common
-
-import gi
-gi.require_versions({'GLib': '2.0', 'Hinawa': '4.0'})
-from gi.repository import GLib, Hinawa
-
-# Qt5 python binding
-from PyQt5.QtWidgets import (
- QApplication,
- QWidget,
- QHBoxLayout,
- QVBoxLayout,
- QToolButton,
- QGroupBox,
- QLineEdit,
- QLabel,
-)
-
-
-def main() -> int:
- if len(argv) < 2:
- msg = ('One argument is required for path to special file of Linux FireWire character '
- 'device')
- common.print_help_with_msg(Path(__file__).name, msg)
- return 1
- cmd, literal = argv[:2]
-
- try:
- path = common.detect_fw_cdev(literal)
- except Exception as e:
- common.print_help_with_msg(cmd, str(e))
- return 1
-
- try:
- node = Hinawa.FwNode.new()
- _ = node.open(str(path), 0)
- common.print_fw_node_information(node)
- except Exception as e:
- msg = str(e)
- common.print_help_with_msg(cmd, msg)
- return 1
-
- with common.listen_node_event(node, path):
- app = QApplication(argv)
- sample = Sample(app, node)
- node.connect('disconnected', lambda n, a: a.quit(), app)
-
- sample.show()
- app.exec()
-
- return 0
-
-
-class Sample(QWidget):
- def __init__(self, app, node):
- super(Sample, self).__init__()
-
- self.node = node
- self.req = Hinawa.FwReq.new()
-
- self.setWindowTitle("Hinawa-4.0 gir sample")
-
- layout = QVBoxLayout()
- self.setLayout(layout)
-
- top_grp = QGroupBox(self)
- top_layout = QHBoxLayout()
- top_grp.setLayout(top_layout)
- layout.addWidget(top_grp)
-
- buttom_grp = QGroupBox(self)
- buttom_layout = QHBoxLayout()
- buttom_grp.setLayout(buttom_layout)
- layout.addWidget(buttom_grp)
-
- button = QToolButton(top_grp)
- button.setText('Read')
- top_layout.addWidget(button)
- button.clicked.connect(self.run_transaction)
-
- close = QToolButton(top_grp)
- close.setText('Close')
- top_layout.addWidget(close)
- close.clicked.connect(app.quit)
-
- self.addr = QLineEdit(buttom_grp)
- self.addr.setText('0xfffff0000980')
- buttom_layout.addWidget(self.addr)
-
- self.value = QLabel(buttom_grp)
- self.value.setText('00000000')
- buttom_layout.addWidget(self.value)
-
- # handle unix signal
- GLib.unix_signal_add(GLib.PRIORITY_HIGH, SIGINT, lambda a: a.quit(), app)
-
- def run_transaction(self, val):
- addr = int(self.addr.text(), 16)
- frames = [0] * 4
-
- try:
- quadlet = common.read_quadlet(self.node, self.req, addr)
- except Exception as e:
- print(e)
-
- label = '0x{:08x}'.format(quadlet)
- self.value.setText(label)
-
-if __name__ == '__main__':
- exit(main())