@@ -80,6 +80,17 @@ impl Dispatcher {
80
80
self . new_http_stream . set ( Some ( callback) ) ;
81
81
}
82
82
83
+ fn register_callout ( & self , token_id : u32 ) {
84
+ if self
85
+ . callouts
86
+ . borrow_mut ( )
87
+ . insert ( token_id, self . active_id . get ( ) )
88
+ . is_some ( )
89
+ {
90
+ panic ! ( "duplicate token_id" )
91
+ }
92
+ }
93
+
83
94
fn create_root_context ( & self , context_id : u32 ) {
84
95
let new_context = match self . new_root . get ( ) {
85
96
Some ( f) => f ( context_id) ,
@@ -96,12 +107,15 @@ impl Dispatcher {
96
107
}
97
108
98
109
fn create_stream_context ( & self , context_id : u32 , root_context_id : u32 ) {
99
- if !self . roots . borrow ( ) . contains_key ( & root_context_id) {
100
- panic ! ( "invalid root_context_id" )
101
- }
102
- let new_context = match self . new_stream . get ( ) {
103
- Some ( f) => f ( context_id, root_context_id) ,
104
- None => panic ! ( "missing constructor" ) ,
110
+ let new_context = match self . roots . borrow ( ) . get ( & root_context_id) {
111
+ Some ( root_context) => match self . new_stream . get ( ) {
112
+ Some ( f) => f ( context_id, root_context_id) ,
113
+ None => match root_context. create_stream_context ( context_id) {
114
+ Some ( stream_context) => stream_context,
115
+ None => panic ! ( "create_stream_context returned None" ) ,
116
+ } ,
117
+ } ,
118
+ None => panic ! ( "invalid root_context_id" ) ,
105
119
} ;
106
120
if self
107
121
. streams
@@ -114,12 +128,15 @@ impl Dispatcher {
114
128
}
115
129
116
130
fn create_http_context ( & self , context_id : u32 , root_context_id : u32 ) {
117
- if !self . roots . borrow ( ) . contains_key ( & root_context_id) {
118
- panic ! ( "invalid root_context_id" )
119
- }
120
- let new_context = match self . new_http_stream . get ( ) {
121
- Some ( f) => f ( context_id, root_context_id) ,
122
- None => panic ! ( "missing constructor" ) ,
131
+ let new_context = match self . roots . borrow ( ) . get ( & root_context_id) {
132
+ Some ( root_context) => match self . new_http_stream . get ( ) {
133
+ Some ( f) => f ( context_id, root_context_id) ,
134
+ None => match root_context. create_http_context ( context_id) {
135
+ Some ( stream_context) => stream_context,
136
+ None => panic ! ( "create_http_context returned None" ) ,
137
+ } ,
138
+ } ,
139
+ None => panic ! ( "invalid root_context_id" ) ,
123
140
} ;
124
141
if self
125
142
. http_streams
@@ -131,26 +148,25 @@ impl Dispatcher {
131
148
}
132
149
}
133
150
134
- fn register_callout ( & self , token_id : u32 ) {
135
- if self
136
- . callouts
137
- . borrow_mut ( )
138
- . insert ( token_id, self . active_id . get ( ) )
139
- . is_some ( )
140
- {
141
- panic ! ( "duplicate token_id" )
142
- }
143
- }
144
-
145
151
fn on_create_context ( & self , context_id : u32 , root_context_id : u32 ) {
146
152
if root_context_id == 0 {
147
- self . create_root_context ( context_id)
153
+ self . create_root_context ( context_id) ;
148
154
} else if self . new_http_stream . get ( ) . is_some ( ) {
149
155
self . create_http_context ( context_id, root_context_id) ;
150
156
} else if self . new_stream . get ( ) . is_some ( ) {
151
157
self . create_stream_context ( context_id, root_context_id) ;
158
+ } else if let Some ( root_context) = self . roots . borrow ( ) . get ( & root_context_id) {
159
+ match root_context. get_type ( ) {
160
+ Some ( ContextType :: HttpContext ) => {
161
+ self . create_http_context ( context_id, root_context_id)
162
+ }
163
+ Some ( ContextType :: StreamContext ) => {
164
+ self . create_stream_context ( context_id, root_context_id)
165
+ }
166
+ None => panic ! ( "missing ContextType on root_context" ) ,
167
+ }
152
168
} else {
153
- panic ! ( "missing constructors" )
169
+ panic ! ( "invalid root_context_id and missing constructors" ) ;
154
170
}
155
171
}
156
172
0 commit comments