|
1 /* Copyright 2004-2006 BBN Technologies Corporation |
|
2 * |
|
3 * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
|
4 * use this file except in compliance with the License. You may obtain a copy |
|
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0 |
|
6 * |
|
7 * Unless required by applicable law or agreed to in writing, software |
|
8 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
|
9 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
10 * |
|
11 * See the License for the specific language governing permissions and |
|
12 * limitations under the License. |
|
13 * |
|
14 */ |
|
15 |
|
16 #ifdef HAVE_CONFIG_H |
|
17 # include <dtn-config.h> |
|
18 #endif |
|
19 |
|
20 #if defined(XERCES_C_ENABLED) && defined(EXTERNAL_CL_ENABLED) |
|
21 |
|
22 #include <exception> |
|
23 #include <oasys/serialize/XMLSerialize.h> |
|
24 |
|
25 #include "CLEventHandler.h" |
|
26 |
|
27 |
|
28 namespace dtn { |
|
29 |
|
30 |
|
31 void |
|
32 CLEventHandler::dispatch_cl_event(cl_message* message) |
|
33 { |
|
34 #define DISPATCH_MESSAGE(message_name) do { \ |
|
35 if ( message->message_name().present() ) { \ |
|
36 log_debug_p("/dtn/cl/dispatcher", "Dispatching " #message_name); \ |
|
37 handle( message->message_name().get() ); \ |
|
38 } } while (false); |
|
39 |
|
40 DISPATCH_MESSAGE(cla_add_request); |
|
41 DISPATCH_MESSAGE(cla_delete_request); |
|
42 DISPATCH_MESSAGE(cla_params_set_event); |
|
43 DISPATCH_MESSAGE(interface_created_event); |
|
44 DISPATCH_MESSAGE(interface_reconfigured_event); |
|
45 DISPATCH_MESSAGE(eid_reachable_event); |
|
46 DISPATCH_MESSAGE(link_created_event); |
|
47 DISPATCH_MESSAGE(link_opened_event); |
|
48 DISPATCH_MESSAGE(link_closed_event); |
|
49 DISPATCH_MESSAGE(link_state_changed_event); |
|
50 DISPATCH_MESSAGE(link_deleted_event); |
|
51 DISPATCH_MESSAGE(link_attribute_changed_event); |
|
52 DISPATCH_MESSAGE(contact_attribute_changed_event); |
|
53 DISPATCH_MESSAGE(link_add_reachable_event); |
|
54 DISPATCH_MESSAGE(bundle_transmitted_event); |
|
55 DISPATCH_MESSAGE(bundle_canceled_event); |
|
56 DISPATCH_MESSAGE(bundle_receive_started_event); |
|
57 DISPATCH_MESSAGE(bundle_received_event); |
|
58 DISPATCH_MESSAGE(report_eid_reachable); |
|
59 DISPATCH_MESSAGE(report_link_attributes); |
|
60 DISPATCH_MESSAGE(report_interface_attributes); |
|
61 DISPATCH_MESSAGE(report_cla_parameters); |
|
62 |
|
63 #undef DISPATCH_MESSAGE |
|
64 } |
|
65 |
|
66 void |
|
67 CLEventHandler::process_cl_event(const char* msg_buffer, |
|
68 oasys::XercesXMLUnmarshal& parser) |
|
69 { |
|
70 // clear any error condition before next parse |
|
71 parser.reset_error(); |
|
72 |
|
73 std::auto_ptr<cl_message> message; |
|
74 |
|
75 const xercesc::DOMDocument* document = parser.doc(msg_buffer); |
|
76 if (!document) { |
|
77 log_debug_p("/dtn/cl/parse", "Unable to parse document"); |
|
78 return; |
|
79 } |
|
80 |
|
81 try { message = cl_message_(*document); } |
|
82 catch (std::exception& e) { |
|
83 log_debug_p( "/dtn/cl/parse", "Parse error: %s", e.what() ); |
|
84 return; |
|
85 } |
|
86 |
|
87 dispatch_cl_event( message.get() ); |
|
88 } |
|
89 |
|
90 /*void |
|
91 CLEventHandler::clear_parser(oasys::XMLUnmarshal& parser) |
|
92 { |
|
93 const char* event_tag; |
|
94 |
|
95 while ( ( event_tag = parser.parse(NULL) ) ) |
|
96 delete event_tag; |
|
97 }*/ |
|
98 |
|
99 } // namespace dtn |
|
100 |
|
101 #endif // XERCES_C_ENABLED && EXTERNAL_CL_ENABLED |