Skip to content

Commit

Permalink
D-Bus tool to send PC/SC events as D-Bus events.
Browse files Browse the repository at this point in the history
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
LudovicRousseau committed Oct 8, 2011
1 parent 98c0cb0 commit 37187a3
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
3 changes: 3 additions & 0 deletions dbus/README
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
73 changes: 73 additions & 0 deletions dbus/pcsc_watcher.py
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()

0 comments on commit 37187a3

Please sign in to comment.