From: Razvan Deaconescu Date: Mon, 22 Aug 2011 10:37:04 +0000 (+0300) Subject: ppf: Add SwarmWriter class. X-Git-Url: http://p2p-next.cs.pub.ro/gitweb/?a=commitdiff_plain;h=361cd41a8bd03e133ce01963bcfdf6ce0319f3da;p=cs-p2p-next.git ppf: Add SwarmWriter class. --- diff --git a/ppf/new/storage.py b/ppf/new/storage.py index f771f00..cb47b5f 100644 --- a/ppf/new/storage.py +++ b/ppf/new/storage.py @@ -579,3 +579,42 @@ class MySQLDatabaseAccess(DatabaseAccess): def add_verbose_message(self, msg): pass + +class SwarmWriter(object): + """ + Wrapper class for swarm storage write actions. Multiple *Access + objects may be added to the clas resulting in multiple storage types. + For example, adding a swarm could result in + * adding a table entry in a MySQL database (MySQLDatabaseAccess) + * adding a table entry in an SQLite database (SQLiteDatabaseAccess) + * adding a new folder in a tree structure (TreeTextFileAccess) + """ + + def __init__(self): + handlers = [] + + def add_access_handle(self, handle): + handlers.append(handle) + + def remove_access_handle(self, handle): + handlers.remove(handle) + + def add_swarm(self, swarm): + for h in handlers: + h.add_swarm(swarm) + + def add_client_session(self, session): + for h in handlers: + h.add_client_session(swarm) + + def add_peer_status_message(self, msg): + for h in handlers: + h.add_peer_status_message(swarm) + + def add_status_message(self, msg): + for h in handlers: + h.add_status_message(swarm) + + def add_verbose_message(self, msg): + for h in handlers: + h.add_verbose_message(swarm)