Commit fe2f6fd6 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Link requests and answers together.

Ask/Answer packets are linked together in both direction.
The response flag is automaticaly assigned on the answer packet.
The special 'Error' packet can be used as an expected answer for any
non-ask packet.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@1677 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 2888f3be
...@@ -208,6 +208,8 @@ class Packet(object): ...@@ -208,6 +208,8 @@ class Packet(object):
a tuple respectively. a tuple respectively.
""" """
_request = None
_answer = None
_body = None _body = None
_code = None _code = None
_args = None _args = None
...@@ -280,6 +282,9 @@ class Packet(object): ...@@ -280,6 +282,9 @@ class Packet(object):
def isResponse(self): def isResponse(self):
return self._code & RESPONSE_MASK == RESPONSE_MASK return self._code & RESPONSE_MASK == RESPONSE_MASK
def getAnswer(self):
return self._answer
class Ping(Packet): class Ping(Packet):
""" """
...@@ -1224,12 +1229,24 @@ class Error(Packet): ...@@ -1224,12 +1229,24 @@ class Error(Packet):
StaticRegistry = {} StaticRegistry = {}
def register(code, cls): def register(code, request, answer=None):
""" Register a packet in the packet registry """ """ Register a packet in the packet registry """
assert code not in StaticRegistry, "Duplicate packet code" # register the request
cls._code = code # assert code & RESPONSE_MASK == 0
StaticRegistry[code] = cls assert code not in StaticRegistry, "Duplicate request packet code"
return cls request._code = code
request._answer = answer
StaticRegistry[code] = request
if answer not in (None, Error):
# compute the answer code
code = code | RESPONSE_MASK
answer._request = request
answer._code = code
# and register the answer packet
assert code not in StaticRegistry, "Duplicate response packet code"
StaticRegistry[code] = answer
return (request, answer)
return request
class PacketRegistry(dict): class PacketRegistry(dict):
...@@ -1263,70 +1280,119 @@ class PacketRegistry(dict): ...@@ -1263,70 +1280,119 @@ class PacketRegistry(dict):
# packets registration # packets registration
Error = register(0x8000, Error) Error = register(0x8000, Error)
Ping = register(0x0001, Ping) Ping, Pong = register(
Pong = register(0x8001, Pong) 0x0001,
RequestIdentification = register(0x0002, RequestIdentification) Ping,
AcceptIdentification = register(0x8002, AcceptIdentification) Pong)
AskPrimary = register(0x0003, AskPrimary) RequestIdentification, AcceptIdentification = register(
AnswerPrimary = register(0x8003, AnswerPrimary) 0x0002,
RequestIdentification,
AcceptIdentification)
AskPrimary, AnswerPrimary = register(
0x0003,
AskPrimary,
AnswerPrimary)
AnnouncePrimary = register(0x0004, AnnouncePrimary) AnnouncePrimary = register(0x0004, AnnouncePrimary)
ReelectPrimary = register(0x0005, ReelectPrimary) ReelectPrimary = register(0x0005, ReelectPrimary)
NotifyNodeInformation = register(0x0006, NotifyNodeInformation) NotifyNodeInformation = register(0x0006, NotifyNodeInformation)
AskLastIDs = register(0x0007, AskLastIDs) AskLastIDs, AnswerLastIDs = register(
AnswerLastIDs = register(0x8007, AnswerLastIDs) 0x0007,
AskPartitionTable = register(0x0008, AskPartitionTable) AskLastIDs,
AnswerPartitionTable = register(0x8008, AnswerPartitionTable) AnswerLastIDs)
AskPartitionTable, AnswerPartitionTable = register(
0x0008,
AskPartitionTable,
AnswerPartitionTable)
SendPartitionTable = register(0x0009, SendPartitionTable) SendPartitionTable = register(0x0009, SendPartitionTable)
NotifyPartitionChanges = register(0x000A, NotifyPartitionChanges) NotifyPartitionChanges = register(0x000A, NotifyPartitionChanges)
StartOperation = register(0x000B, StartOperation) StartOperation = register(0x000B, StartOperation)
StopOperation = register(0x000C, StopOperation) StopOperation = register(0x000C, StopOperation)
AskUnfinishedTransactions = register(0x000D, AskUnfinishedTransactions) AskUnfinishedTransactions, AnswerUnfinishedTransactions = register(
AnswerUnfinishedTransactions = register(0x800d, 0x000D,
AskUnfinishedTransactions,
AnswerUnfinishedTransactions) AnswerUnfinishedTransactions)
AskObjectPresent = register(0x000f, AskObjectPresent) AskObjectPresent, AnswerObjectPresent = register(
AnswerObjectPresent = register(0x800f, AnswerObjectPresent) 0x000f,
AskObjectPresent,
AnswerObjectPresent)
DeleteTransaction = register(0x0010, DeleteTransaction) DeleteTransaction = register(0x0010, DeleteTransaction)
CommitTransaction = register(0x0011, CommitTransaction) CommitTransaction = register(0x0011, CommitTransaction)
AskBeginTransaction = register(0x0012, AskBeginTransaction) AskBeginTransaction, AnswerBeginTransaction = register(
AnswerBeginTransaction = register(0x8012, AnswerBeginTransaction) 0x0012,
AskFinishTransaction = register(0x0013, AskFinishTransaction) AskBeginTransaction,
AnswerTransactionFinished = register(0x8013, AnswerTransactionFinished) AnswerBeginTransaction)
AskLockInformation = register(0x0014, AskLockInformation) AskFinishTransaction, AnswerTransactionFinished = register(
AnswerInformationLocked = register(0x8014, AnswerInformationLocked) 0x0013,
AskFinishTransaction,
AnswerTransactionFinished)
AskLockInformation, AnswerInformationLocked = register(
0x0014,
AskLockInformation,
AnswerInformationLocked)
InvalidateObjects = register(0x0015, InvalidateObjects) InvalidateObjects = register(0x0015, InvalidateObjects)
NotifyUnlockInformation = register(0x0016, NotifyUnlockInformation) NotifyUnlockInformation = register(0x0016, NotifyUnlockInformation)
AskNewOIDs = register(0x0017, AskNewOIDs) AskNewOIDs, AnswerNewOIDs = register(
AnswerNewOIDs = register(0x8017, AnswerNewOIDs) 0x0017,
AskStoreObject = register(0x0018, AskStoreObject) AskNewOIDs,
AnswerStoreObject = register(0x8018, AnswerStoreObject) AnswerNewOIDs)
AskStoreObject, AnswerStoreObject = register(
0x0018,
AskStoreObject,
AnswerStoreObject)
AbortTransaction = register(0x0019, AbortTransaction) AbortTransaction = register(0x0019, AbortTransaction)
AskStoreTransaction = register(0x001A, AskStoreTransaction) AskStoreTransaction, AnswerStoreTransaction = register(
AnswerStoreTransaction = register(0x801A, AnswerStoreTransaction) 0x001A,
AskObject = register(0x001B, AskObject) AskStoreTransaction,
AnswerObject = register(0x801B, AnswerObject) AnswerStoreTransaction)
AskTIDs = register(0x001C, AskTIDs) AskObject, AnswerObject = register(
AnswerTIDs = register(0x801D, AnswerTIDs) 0x001B,
AskTransactionInformation = register(0x001E, AskTransactionInformation) AskObject,
AnswerTransactionInformation = register(0x801E, AnswerObject)
AskTIDs, AnswerTIDs = register(
0x001C,
AskTIDs,
AnswerTIDs)
AskTransactionInformation, AnswerTransactionInformation = register(
0x001E,
AskTransactionInformation,
AnswerTransactionInformation) AnswerTransactionInformation)
AskObjectHistory = register(0x001F, AskObjectHistory) AskObjectHistory, AnswerObjectHistory = register(
AnswerObjectHistory = register(0x801F, AnswerObjectHistory) 0x001F,
AskOIDs = register(0x0020, AskOIDs) AskObjectHistory,
AnswerOIDs = register(0x8020, AnswerOIDs) AnswerObjectHistory)
AskPartitionList = register(0x0021, AskPartitionList) AskOIDs, AnswerOIDs = register(
AnswerPartitionList = register(0x8021, AnswerPartitionList) 0x0020,
AskNodeList = register(0x0022, AskNodeList) AskOIDs,
AnswerNodeList = register(0x8022, AnswerNodeList) AnswerOIDs)
SetNodeState = register(0x0023, SetNodeState) AskPartitionList, AnswerPartitionList = register(
AnswerNodeState = register(0x8023, AnswerNodeState) 0x0021,
AddPendingNodes = register(0x0024, AddPendingNodes) AskPartitionList,
AnswerNewNodes = register(0x8024, AnswerNewNodes) AnswerPartitionList)
AskNodeInformation = register(0x0025, AskNodeInformation) AskNodeList, AnswerNodeList = register(
AnswerNodeInformation = register(0x8025, AnswerNodeInformation) 0x0022,
SetClusterState = register(0x0026, SetClusterState) AskNodeList,
AnswerNodeList)
SetNodeState, AnswerNodeState = register(
0x0023,
SetNodeState,
AnswerNodeState)
AddPendingNodes, AnswerNewNodes = register(
0x0024,
AddPendingNodes,
AnswerNewNodes)
AskNodeInformation, AnswerNodeInformation = register(
0x0025,
AskNodeInformation,
AnswerNodeInformation)
SetClusterState = register(
0x0026,
SetClusterState,
Error)
NotifyClusterInformation = register(0x0027, NotifyClusterInformation) NotifyClusterInformation = register(0x0027, NotifyClusterInformation)
AskClusterState = register(0x0028, AskClusterState) AskClusterState, AnswerClusterState = register(
AnswerClusterState = register(0x8028, AnswerClusterState) 0x0028,
AskClusterState,
AnswerClusterState)
NotifyLastOID = register(0x0030, NotifyLastOID) NotifyLastOID = register(0x0030, NotifyLastOID)
NotifyReplicationDone = register(0x0031, NotifyReplicationDone) NotifyReplicationDone = register(0x0031, NotifyReplicationDone)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment