Commit 449041ae1f4156ff1418ee17235ec03f72a4f349

Authored by Georg Hopp
1 parent a2bef391

add io handler

@@ -4,6 +4,7 @@ nobase_include_HEADERS = tr/comm_end_point.h \ @@ -4,6 +4,7 @@ nobase_include_HEADERS = tr/comm_end_point.h \
4 tr/connect_entry_point.h \ 4 tr/connect_entry_point.h \
5 tr/connection.h \ 5 tr/connection.h \
6 tr/connector.h \ 6 tr/connector.h \
  7 + tr/io_handler.h \
7 tr/proto_message.h \ 8 tr/proto_message.h \
8 tr/protocol.h \ 9 tr/protocol.h \
9 tr/protocol_handler.h \ 10 tr/protocol_handler.h \
@@ -7,6 +7,7 @@ @@ -7,6 +7,7 @@
7 #include "tr/connect_entry_point.h" 7 #include "tr/connect_entry_point.h"
8 #include "tr/connection.h" 8 #include "tr/connection.h"
9 #include "tr/connector.h" 9 #include "tr/connector.h"
  10 +#include "tr/io_handler.h"
10 #include "tr/proto_message.h" 11 #include "tr/proto_message.h"
11 #include "tr/protocol.h" 12 #include "tr/protocol.h"
12 #include "tr/protocol_handler.h" 13 #include "tr/protocol_handler.h"
@@ -17,6 +17,7 @@ TRCOMM = cep_append_read_data.c \ @@ -17,6 +17,7 @@ TRCOMM = cep_append_read_data.c \
17 conn_entry_point.c \ 17 conn_entry_point.c \
18 connection.c \ 18 connection.c \
19 connector.c \ 19 connector.c \
  20 + io_handler.c \
20 proto_message.c \ 21 proto_message.c \
21 protocol.c \ 22 protocol.c \
22 protocol_handler.c \ 23 protocol_handler.c \
@@ -25,10 +25,7 @@ @@ -25,10 +25,7 @@
25 #include "trbase.h" 25 #include "trbase.h"
26 #include "trevent.h" 26 #include "trevent.h"
27 27
28 -#include "tr/protocol.h"  
29 -#include "tr/connection.h"  
30 -#include "tr/protocol_handler.h"  
31 -#include "tr/proto_message.h" 28 +#include "tr/io_handler.h"
32 #include "tr/comm_end_point.h" 29 #include "tr/comm_end_point.h"
33 #include "tr/interface/comm_end_point.h" 30 #include "tr/interface/comm_end_point.h"
34 31
@@ -47,11 +44,15 @@ static @@ -47,11 +44,15 @@ static
47 int 44 int
48 ioHandlerRead(void * _this, TR_Event event) 45 ioHandlerRead(void * _this, TR_Event event)
49 { 46 {
50 - /**  
51 - * TODO No upgrade for now. Add it later on.  
52 - */  
53 TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject; 47 TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject;
54 - TR_ProtoMessage message = TR_cepNextMessage(endpoint); 48 +
  49 + if (TR_cepBufferRead(endpoint)) {
  50 + TR_eventHandlerIssueEvent(
  51 + (TR_EventHandler)_this,
  52 + event->subject,
  53 + TR_CEP_EVENT_NEW_DATA,
  54 + NULL);
  55 + }
55 56
56 return TRUE; 57 return TRUE;
57 } 58 }
@@ -61,12 +62,21 @@ int @@ -61,12 +62,21 @@ int
61 ioHandlerWrite(void * _this, TR_Event event) 62 ioHandlerWrite(void * _this, TR_Event event)
62 { 63 {
63 TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject; 64 TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject;
64 - TR_ProtoMessage message = (TR_ProtoMessage)event->data;  
65 65
66 - if (message->close) {  
67 - // also check that we are a response. Well this is how it is done  
68 - // in the python code...  
69 - TR_cepSetClose(endpoint); 66 + if (TR_cepWriteBuffered(endpoint)) {
  67 + if (TR_cepHasPendingData(endpoint)) {
  68 + TR_eventHandlerIssueEvent(
  69 + (TR_EventHandler)_this,
  70 + event->subject,
  71 + TR_CEP_EVENT_PENDING_DATA,
  72 + NULL);
  73 + } else {
  74 + TR_eventHandlerIssueEvent(
  75 + (TR_EventHandler)_this,
  76 + event->subject,
  77 + TR_CEP_EVENT_END_DATA,
  78 + NULL);
  79 + }
70 } 80 }
71 81
72 return TRUE; 82 return TRUE;
@@ -74,17 +84,17 @@ ioHandlerWrite(void * _this, TR_Event event) @@ -74,17 +84,17 @@ ioHandlerWrite(void * _this, TR_Event event)
74 84
75 static 85 static
76 void 86 void
77 -protocolHandlerCvInit(TR_class_ptr cls) 87 +ioHandlerCvInit(TR_class_ptr cls)
78 { 88 {
79 TR_EVENT_HANDLER_SET_METHOD( 89 TR_EVENT_HANDLER_SET_METHOD(
80 cls, 90 cls,
81 - TR_Connection, 91 + TR_CommEndPoint,
82 TR_CEP_EVENT_READ_READY, 92 TR_CEP_EVENT_READ_READY,
83 ioHandlerRead); 93 ioHandlerRead);
84 94
85 TR_EVENT_HANDLER_SET_METHOD( 95 TR_EVENT_HANDLER_SET_METHOD(
86 cls, 96 cls,
87 - TR_Connection, 97 + TR_CommEndPoint,
88 TR_CEP_EVENT_WRITE_READY, 98 TR_CEP_EVENT_WRITE_READY,
89 ioHandlerWrite); 99 ioHandlerWrite);
90 } 100 }
@@ -92,7 +102,7 @@ protocolHandlerCvInit(TR_class_ptr cls) @@ -92,7 +102,7 @@ protocolHandlerCvInit(TR_class_ptr cls)
92 TR_INSTANCE(TR_Hash, ioHandlerEventMethods); 102 TR_INSTANCE(TR_Hash, ioHandlerEventMethods);
93 TR_INIT_IFACE(TR_Class, ioHandlerCtor, ioHandlerDtor, NULL); 103 TR_INIT_IFACE(TR_Class, ioHandlerCtor, ioHandlerDtor, NULL);
94 TR_CREATE_CLASS( 104 TR_CREATE_CLASS(
95 - TR_ProtocolHandler, 105 + TR_IoHandler,
96 TR_EventHandler, 106 TR_EventHandler,
97 ioHandlerCvInit, 107 ioHandlerCvInit,
98 TR_IF(TR_Class)) = { 108 TR_IF(TR_Class)) = {
@@ -108,19 +108,19 @@ protocolHandlerCvInit(TR_class_ptr cls) @@ -108,19 +108,19 @@ protocolHandlerCvInit(TR_class_ptr cls)
108 { 108 {
109 TR_EVENT_HANDLER_SET_METHOD( 109 TR_EVENT_HANDLER_SET_METHOD(
110 cls, 110 cls,
111 - TR_Connection, 111 + TR_CommEndPoint,
112 TR_CEP_EVENT_NEW_DATA, 112 TR_CEP_EVENT_NEW_DATA,
113 protocolHandlerParse); 113 protocolHandlerParse);
114 114
115 TR_EVENT_HANDLER_SET_METHOD( 115 TR_EVENT_HANDLER_SET_METHOD(
116 cls, 116 cls,
117 - TR_Connection, 117 + TR_CommEndPoint,
118 TR_CEP_EVENT_SEND_MSG, 118 TR_CEP_EVENT_SEND_MSG,
119 protocolHandlerCompose); 119 protocolHandlerCompose);
120 120
121 TR_EVENT_HANDLER_SET_METHOD( 121 TR_EVENT_HANDLER_SET_METHOD(
122 cls, 122 cls,
123 - TR_Connection, 123 + TR_CommEndPoint,
124 TR_CEP_EVENT_UPGRADE, 124 TR_CEP_EVENT_UPGRADE,
125 protocolHandlerUpgrade); 125 protocolHandlerUpgrade);
126 } 126 }
Please register or login to post a comment