forked from LudovicRousseau/PCSC-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
D-Bus tool to send PC/SC events as D-Bus events.
Thanks to Florian Echtler http:https://old.nabble.com/Re%3A-DBus-signalling-in-pcsc-lite--p32401088.html git-svn-id: svn:https://svn.debian.org/svn/pcsclite/trunk/contrib@6020 0ce88b0d-b2fd-0310-8134-9614164e65ea
- Loading branch information
1 parent
98c0cb0
commit 37187a3
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
No client is provided yet. Use dbus-monitor as a client for now | ||
|
||
Ludovic Rousseau |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#!/usr/bin/env python | ||
|
||
""" | ||
pcsc-watcher.py: send PC/SC events as DBus events | ||
Copyright (C) 2011 Florian "floe" Echtler <[email protected]> | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http:https://www.gnu.org/licenses/>. | ||
""" | ||
|
||
import gobject | ||
|
||
import dbus | ||
import dbus.service | ||
|
||
from dbus.mainloop.glib import DBusGMainLoop | ||
|
||
from smartcard.CardMonitoring import * | ||
from smartcard.util import * | ||
|
||
|
||
# dbus stuff | ||
|
||
service = None | ||
|
||
interface = "org.debian.alioth.pcsclite" # also used as bus name | ||
path = "/org/debian/alioth/pcsclite/reader0/slot0" | ||
|
||
|
||
class PCSC_DBus_Service(dbus.service.Object): | ||
""" very simple DBus service class with one signal """ | ||
def __init__(self, object_path): | ||
bus_name = dbus.service.BusName(interface, bus=dbus.SessionBus()) | ||
dbus.service.Object.__init__(self, bus_name, object_path) | ||
|
||
@dbus.service.signal(interface) | ||
def CardPresenceChanged(self, atr, added): | ||
pass | ||
|
||
|
||
# smartcard stuff | ||
|
||
class PCSC_Card_Observer(CardObserver): | ||
""" simple card observer class which calls the DBus service """ | ||
def update(self, observable, (addedcards, removedcards)): | ||
for card in addedcards: | ||
service.CardPresenceChanged(toHexString(card.atr), True) | ||
for card in removedcards: | ||
service.CardPresenceChanged(toHexString(card.atr), False) | ||
|
||
|
||
# main | ||
|
||
DBusGMainLoop(set_as_default=True) | ||
gobject.threads_init() # very important to avoid starving the PCSC thread | ||
|
||
service = PCSC_DBus_Service(path) | ||
|
||
cardmonitor = CardMonitor() | ||
cardobserver = PCSC_Card_Observer() | ||
cardmonitor.addObserver(cardobserver) | ||
|
||
gobject.MainLoop().run() |