Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

orb->run() How do I need to write code so that the "run()" function exits or throws an exception? #2123

Closed
xpston008 opened this issue Sep 12, 2023 · 0 comments

Comments

@xpston008
Copy link

xpston008 commented Sep 12, 2023

Create a thread to implement event message subscription (pull consumer) client. The client needs to implement a server program and must call orb->run(), but orb->run() is blocked or in a loop state. How to implement external code (send signal) to make orb->run() exit.

I wanted to use "debug mode" to debug run(), but found that I couldn't enter the code. So come for help.
After searching, all common test cases are very simple and of little help to me, as follows:

int main()
{
...
orb->run() ;
return 0;
}

My test code.

void CTmfClient::TestEvenet()
{
	int event_id;
	CosNotifyChannelAdmin::InterFilterGroupOperator method = CosNotifyChannelAdmin::InterFilterGroupOperator::AND_OP;

	CosNotifyChannelAdmin::ConsumerAdmin_ptr  consumerAdmin =  eventChannel->new_for_consumers(method, event_id);
	CosNotification::EventTypeSeq_var add_event_type_hearts = new CosNotification::EventTypeSeq;

	std::map<std::string, std::string>::iterator iter = event_map_list.begin();
	add_event_type_hearts->length(event_map_list.size());
	for (int idx = 0; iter != event_map_list.end(); ++iter,++idx)
	{
		(*add_event_type_hearts)[idx].domain_name = CORBA::string_dup("tmf_mtnm");
		(*add_event_type_hearts)[idx].type_name = CORBA::string_dup(iter->first.c_str());
	}
	CosNotification::EventTypeSeq_var remv_event_type_hearts = new CosNotification::EventTypeSeq;

	consumerAdmin->subscription_change(add_event_type_hearts, remv_event_type_hearts);

	consumerAdmin->remove_all_filters();

	CosNotification::EventTypeSeq_var add_event_type_alarms = new CosNotification::EventTypeSeq;
	add_event_type_alarms->length(1);
	(*add_event_type_hearts)[0].domain_name = CORBA::string_dup("tmf_mtnm");
	(*add_event_type_hearts)[0].type_name = CORBA::string_dup("NT_ALARM");
	CosNotifyFilter::ConstraintExpSeq_var alarmExps = new CosNotifyFilter::ConstraintExpSeq;
	alarmExps->length(2);
	(*alarmExps)[0].event_types = add_event_type_alarms;
	(*alarmExps)[0].constraint_expr = CORBA::string_dup("1==1");
	(*alarmExps)[1].event_types = add_event_type_alarms;
	(*alarmExps)[1].constraint_expr = CORBA::string_dup("1==1");

	CosNotifyFilter::FilterFactory_ptr filterFactory = eventChannel->default_filter_factory();
	CosNotifyFilter::Filter_ptr alarmFilter = filterFactory->create_filter("TCL");
	try
	{
		alarmFilter->add_constraints(alarmExps);
	}
	catch (CosNotifyFilter::InvalidConstraint & e)
	{
		std::cout << e.constr.constraint_expr;
	}
	consumerAdmin->add_filter(alarmFilter);
	EventConsumer * eventConsumer = new EventConsumer;
	CosNotifyComm::StructuredPushConsumer_ptr pushConsumer = eventConsumer->_this();
	int proxy_id;
	CosNotifyChannelAdmin::ProxySupplier_ptr proxySupplier = consumerAdmin->obtain_notification_push_supplier(CosNotifyChannelAdmin::ClientType::STRUCTURED_EVENT, proxy_id);

	CosNotifyChannelAdmin::StructuredProxyPushSupplier_ptr proxyPushSupplier = CosNotifyChannelAdmin::StructuredProxyPushSupplier::_narrow(proxySupplier);


	proxyPushSupplier->connect_structured_push_consumer(pushConsumer);

	Any::setDaf(GetAnyFactory());
	orb->run();// Blocked state or loop state, what signal is sent to make the function jump out of the loop or blocked state, and how to implement the code?

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant