-- ----------------------------------------------------------------------------{- |
Module : Holumbus.Network.PortRegistry.PortRegistryData
Copyright : Copyright (C) 2008 Stefan Schmidt
License : MIT
Maintainer : Stefan Schmidt (stefanschmidt@web.de)
Stability : experimental
Portability: portable
Version : 0.1
This module contains the main datatype for the PortRegistry.
-}-- ----------------------------------------------------------------------------moduleHolumbus.Network.PortRegistry.PortRegistryData{-# DEPRECATED "this module will be remove in the next release, please use the packages from Holumbus.Distribution.*" #-}(-- * DatatypesPortRegistryData-- * Creation and Destruction,newPortRegistryData,closePortRegistryData,getPortRegistryRequestPort-- * reexport,setPortRegistry)whereimportControl.ConcurrentimportqualifiedData.MapasMapimportNetworkimportSystem.Log.LoggerimportHolumbus.Common.ThreadingimportHolumbus.Network.PortimportHolumbus.Network.MessagesimportHolumbus.Network.PortRegistryimportHolumbus.Network.PortRegistry.MessageslocalLogger::StringlocalLogger="Holumbus.Network.PortRegistry.PortRegistryData"-- ------------------------------------------------------------------------------ Datatypes-- ------------------------------------------------------------------------------ | The data needed by the PortRegistrydataPortRegistryData=PortRegistryData{prd_ServerThreadId::Thread-- ^ The thread-data of the message-dispatcher thread.,prd_OwnStream::PortRegistryRequestStream-- ^ The Stream for all incomming messages.,prd_SocketMap::MVar(Map.MapStreamNameSocketId)-- ^ The map storing the port-data (the real registry).}-- ------------------------------------------------------------------------------ Creation and Destruction-- ------------------------------------------------------------------------------ | Creates a new PortRegistry.newPortRegistryData::StreamName->MaybePortNumber->IOPortRegistryDatanewPortRegistryDatasnpn=dost<-(newStreamSTLocal(Justsn)pn)::IOPortRegistryRequestStreammMVar<-newMVarMap.emptysMVar<-newThreadletprd=PortRegistryDatasMVarstmMVarstartRequestDispatchersMVarst(dispatchprd)returnprd-- | Closes the PortRegistry with its streams and threads.closePortRegistryData::PortRegistryData->IO()closePortRegistryDataprd=dostopRequestDispatcher(prd_ServerThreadIdprd)closeStream(prd_OwnStreamprd)return()-- | Get the RequestPort of the PortRegistry.-- It can be used to give access to the PortRegistry, eg. you can serialize-- this information and transfer it over the network to grant access to the-- clients.getPortRegistryRequestPort::PortRegistryData->IOPortRegistryRequestPortgetPortRegistryRequestPortprd=newPortFromStream(prd_OwnStreamprd)-- | The main dispatch-function. It handles the incomming messages and reacts.dispatch::PortRegistryData->PortRegistryRequestMessage->PortRegistryResponsePort->IO()dispatchprdmsgreplyPort=docasemsgof(PRReqRegistersnsoid)->dohandleRequestreplyPort(registerPortsnsoidprd)(\_->PRRspSuccess)return()(PRReqUnregistersn)->dohandleRequestreplyPort(unregisterPortsnprd)(\_->PRRspSuccess)return()(PRReqLookupsn)->dohandleRequestreplyPort(lookupPortsnprd)(\soid->PRRspLookupsoid)return()(PRReqGetPorts)->dohandleRequestreplyPort(getPortsprd)(\ls->PRRspGetPortsls)return()_->doinfoMlocalLogger$"dispatch: unknown request "++showmsghandleRequestreplyPort(return())(\_->PRRspUnknown)-- ------------------------------------------------------------------------------ Typeclass instanciation (PortRegistry)-- ------------------------------------------------------------------------------ The PortRegistry-typeclass instanciation for the PortRegistryData.instancePortRegistryPortRegistryDatawhereregisterPortsnsoidprd=doinfoMlocalLogger$"register: "++sn++" - at: "++showsoidmodifyMVar(prd_SocketMapprd)$\sm->return(Map.insertsnsoidsm,())unregisterPortsnprd=doinfoMlocalLogger$"unregister: "++snmodifyMVar(prd_SocketMapprd)$\sm->return(Map.deletesnsm,())lookupPortsnprd=doinfoMlocalLogger$"looking up: "++snsoid<-withMVar(prd_SocketMapprd)$\sm->return(Map.lookupsnsm)infoMlocalLogger$"result for: "++sn++" -> "++showsoidreturnsoidgetPortsprd=doinfoMlocalLogger$"getting all ports"withMVar(prd_SocketMapprd)$\sm->return(Map.toListsm)