ProtocolParser.F90 Source File


This file depends on

sourcefile~~protocolparser.f90~~EfferentGraph sourcefile~protocolparser.f90 ProtocolParser.F90 sourcefile~abstractmessage.f90 AbstractMessage.F90 sourcefile~protocolparser.f90->sourcefile~abstractmessage.f90 sourcefile~addextcollectionmessage.f90 AddExtCollectionMessage.F90 sourcefile~protocolparser.f90->sourcefile~addextcollectionmessage.f90 sourcefile~addhistcollectionmessage.f90 AddHistCollectionMessage.F90 sourcefile~protocolparser.f90->sourcefile~addhistcollectionmessage.f90 sourcefile~collectiveprefetchdatamessage.f90 CollectivePrefetchDataMessage.F90 sourcefile~protocolparser.f90->sourcefile~collectiveprefetchdatamessage.f90 sourcefile~collectiveprefetchdonemessage.f90 CollectivePrefetchDoneMessage.F90 sourcefile~protocolparser.f90->sourcefile~collectiveprefetchdonemessage.f90 sourcefile~collectivestagedatamessage.f90 CollectiveStageDataMessage.F90 sourcefile~protocolparser.f90->sourcefile~collectivestagedatamessage.f90 sourcefile~collectivestagedonemessage.f90 CollectiveStageDoneMessage.F90 sourcefile~protocolparser.f90->sourcefile~collectivestagedonemessage.f90 sourcefile~donemessage.f90 DoneMessage.F90 sourcefile~protocolparser.f90->sourcefile~donemessage.f90 sourcefile~dummymessage.f90 DummyMessage.F90 sourcefile~protocolparser.f90->sourcefile~dummymessage.f90 sourcefile~filemetadata.f90 FileMetadata.F90 sourcefile~protocolparser.f90->sourcefile~filemetadata.f90 sourcefile~forwarddatamessage.f90 ForwardDataMessage.F90 sourcefile~protocolparser.f90->sourcefile~forwarddatamessage.f90 sourcefile~handshakemessage.f90 HandShakeMessage.F90 sourcefile~protocolparser.f90->sourcefile~handshakemessage.f90 sourcefile~idmessage.f90 IDMessage.F90 sourcefile~protocolparser.f90->sourcefile~idmessage.f90 sourcefile~integermessagemap.f90 IntegerMessageMap.F90 sourcefile~protocolparser.f90->sourcefile~integermessagemap.f90 sourcefile~modifymetadatamessage.f90 ModifyMetadataMessage.F90 sourcefile~protocolparser.f90->sourcefile~modifymetadatamessage.f90 sourcefile~prefetchdatamessage.f90 PrefetchDataMessage.F90 sourcefile~protocolparser.f90->sourcefile~prefetchdatamessage.f90 sourcefile~prefetchdonemessage.f90 PrefetchDoneMessage.F90 sourcefile~protocolparser.f90->sourcefile~prefetchdonemessage.f90 sourcefile~replacemetadatamessage.f90 ReplaceMetadataMessage.F90 sourcefile~protocolparser.f90->sourcefile~replacemetadatamessage.f90 sourcefile~stagedatamessage.f90 StageDataMessage.F90 sourcefile~protocolparser.f90->sourcefile~stagedatamessage.f90 sourcefile~stagedonemessage.f90 StageDoneMessage.F90 sourcefile~protocolparser.f90->sourcefile~stagedonemessage.f90 sourcefile~terminatemessage.f90 TerminateMessage.F90 sourcefile~protocolparser.f90->sourcefile~terminatemessage.f90

Files dependent on this one

sourcefile~~protocolparser.f90~~AfferentGraph sourcefile~protocolparser.f90 ProtocolParser.F90 sourcefile~directoryservice.f90 DirectoryService.F90 sourcefile~directoryservice.f90->sourcefile~protocolparser.f90 sourcefile~mpisocket.f90 MpiSocket.F90 sourcefile~directoryservice.f90->sourcefile~mpisocket.f90 sourcefile~messagevector.f90 MessageVector.F90 sourcefile~messagevector.f90->sourcefile~protocolparser.f90 sourcefile~mpisocket.f90->sourcefile~protocolparser.f90 sourcefile~test_mpisocket.pf Test_MpiSocket.pf sourcefile~test_mpisocket.pf->sourcefile~protocolparser.f90 sourcefile~test_mpisocket.pf->sourcefile~mpisocket.f90 sourcefile~test_protocolparser.pf Test_ProtocolParser.pf sourcefile~test_protocolparser.pf->sourcefile~protocolparser.f90 sourcefile~abstractserver.f90 AbstractServer.F90 sourcefile~abstractserver.f90->sourcefile~messagevector.f90 sourcefile~baseserver.f90 BaseServer.F90 sourcefile~baseserver.f90->sourcefile~messagevector.f90 sourcefile~baseserver.f90->sourcefile~mpisocket.f90 sourcefile~forwarddataandmessage.f90 ForwardDataAndMessage.F90 sourcefile~forwarddataandmessage.f90->sourcefile~messagevector.f90 sourcefile~mocksocket.f90 MockSocket.F90 sourcefile~mocksocket.f90->sourcefile~messagevector.f90 sourcefile~multicommserver.f90 MultiCommServer.F90 sourcefile~multicommserver.f90->sourcefile~messagevector.f90 sourcefile~multicommserver.f90->sourcefile~mpisocket.f90 sourcefile~multigroupserver.f90 MultiGroupServer.F90 sourcefile~multigroupserver.f90->sourcefile~messagevector.f90 sourcefile~multigroupserver.f90->sourcefile~mpisocket.f90 sourcefile~multilayerserver.f90 MultiLayerServer.F90 sourcefile~multilayerserver.f90->sourcefile~messagevector.f90 sourcefile~pfio.f90 pFIO.F90 sourcefile~pfio.f90->sourcefile~directoryservice.f90 sourcefile~pfio.f90->sourcefile~mpisocket.f90 sourcefile~pfio_writer.f90 pfio_writer.F90 sourcefile~pfio_writer.f90->sourcefile~messagevector.f90 sourcefile~serverthread.f90 ServerThread.F90 sourcefile~serverthread.f90->sourcefile~messagevector.f90 sourcefile~test_directoryservice.pf Test_DirectoryService.pf sourcefile~test_directoryservice.pf->sourcefile~directoryservice.f90 sourcefile~test_directoryservice.pf->sourcefile~mpisocket.f90

Source Code

#include "unused_dummy.H"
module pFIO_ProtocolParserMod
   use pFIO_AbstractMessageMod
   use pFIO_IntegerMessageMapMod
   use pFIO_FileMetadataMod

   use pFIO_TerminateMessageMod
   use pFIO_DoneMessageMod
   use pFIO_PrefetchDoneMessageMod
   use pFIO_CollectivePrefetchDoneMessageMod
   use pFIO_StageDoneMessageMod
   use pFIO_CollectiveStageDoneMessageMod
   use pFIO_AddExtCollectionMessageMod
   use pFIO_AddHistCollectionMessageMod
   use pFIO_IdMessageMod
   use pFIO_PrefetchDataMessageMod
   use pFIO_StageDataMessageMod
   use pFIO_CollectivePrefetchDataMessageMod
   use pFIO_CollectiveStageDataMessageMod
   use pFIO_ModifyMetadataMessageMod
   use pFIO_ReplaceMetadataMessageMod
   use pFIO_HandShakeMessageMod
   use pFIO_DummyMessageMod
   use pFIO_ForwardDataMessageMod

   implicit none
   private

   public :: ProtocolParser

   type :: ProtocolParser
      private
      type (IntegerMessageMap) :: prototypes
      logical :: initialized = .false.
   contains
      procedure :: initialize
      procedure :: make_message
      procedure :: decode
      procedure :: encode
   end type ProtocolParser

   interface ProtocolParser
      module procedure new_ProtocolParser
   end interface ProtocolParser

contains

   function new_ProtocolParser() result(parser)
      type (ProtocolParser) :: parser

      call parser%initialize()

   end function new_ProtocolParser

   subroutine initialize(this)
      class (ProtocolParser), intent(inout) :: this

      type (TerminateMessage) :: terminate
      type (DoneMessage)                   :: done
      type (PrefetchDoneMessage)           :: pdone
      type (CollectivePrefetchDoneMessage) :: cpdone
      type (StageDoneMessage)              :: sdone
      type (CollectiveStageDoneMessage)    :: csdone
      type (AddExtCollectionMessage)  :: addExtCollection
      type (AddHistCollectionMessage) :: addHistCollection
      type (IdMessage):: IDid
      type (PrefetchDataMessage)    :: PrefetchData
      type (StageDataMessage) :: StageData
      type (CollectivePrefetchDataMessage) :: CollectivePrefetchData
      type (CollectiveStageDataMessage)    :: CollectiveStageData
      type (ModifyMetadataMessage) :: ModifyMetadata
      type (ReplaceMetadataMessage) :: ReplaceMetadata
      type (HandShakeMessage) :: handshake
      type (DummyMessage) :: dummy
      type (ForwardDataMessage) :: ForwardData

      if (this%initialized) return

      call add_prototype(terminate)
      call add_prototype(done)
      call add_prototype(pdone)
      call add_prototype(cpdone)
      call add_prototype(sdone)
      call add_prototype(csdone)
      call add_prototype(addExtCollection)
      addHistCollection = AddHistCollectionMessage(FileMetadata())
      call add_prototype(addHistCollection)
      call add_prototype(IDId)
      call add_prototype(PrefetchData)
      call add_prototype(CollectivePrefetchData)
      call add_prototype(StageData)
      call add_prototype(CollectiveStageData)
      ModifyMetaData = ModifyMetadataMessage(collection_id=-1)
      call add_prototype(ModifyMetadata)
      ReplaceMetaData = ReplaceMetadataMessage(-1, FileMetadata())
      call add_prototype(ReplaceMetadata)
      call add_prototype(handshake)
      call add_prototype(dummy)
      call add_prototype(ForwardData)

      this%initialized = .true.

   contains

      subroutine add_prototype(message)
         class (AbstractMessage), intent(in) :: message

         call this%prototypes%insert(message%get_type_id(), message)
         
      end subroutine add_prototype

   end subroutine initialize


   function make_message(this, type_id) result(message)
      class (AbstractMessage), allocatable :: message
      class (ProtocolParser), intent(in) :: this
      integer, intent(in) :: type_id

      class (AbstractMessage), pointer :: prototype
      
      prototype => this%prototypes%at(type_id)
      allocate(message, source=prototype)
      
   end function make_message


   function encode(this, message) result(buffer)
      integer, allocatable :: buffer(:)
      class (ProtocolParser), intent(in) :: this
      class (AbstractMessage), target, intent(in) :: message

      integer :: length

      length = message%get_length()
      allocate(buffer(1 + length))

      buffer(1) = message%get_type_id()
      call message%serialize(buffer(2:))
      return 
      _UNUSED_DUMMY(this)
   end function encode

   
   function decode(this, buffer) result(message)
      class (ProtocolParser), intent(in) :: this
      class (AbstractMessage), allocatable :: message
      integer, intent(in) :: buffer(:)

      allocate(message, source=this%prototypes%at(buffer(1)))
      call message%deserialize(buffer(2:))
      
   end function decode


end module pFIO_ProtocolParserMod