コード例 #1
0
//..
// Now, we defined a function 'main' in which we create a 'MyOstreamObserver'
// object and assign the address of this object to a 'ball::ObserverAdapter'
// pointer:
//..
    int main(bool verbose)
    {
        bsl::ostringstream     out;
        MyOstreamObserver      myObserver(&out);
        ball::ObserverAdapter *adapter = &myObserver;
//..
// Finally, publish three messages by calling 'publish' method accepting a
// shared-pointer, provided by 'ball::ObserverAdapter', that in turn will call
// the 'publish' method defined in 'MyOstreamObserver':
//..
        bdlt::Datetime         now;
        ball::RecordAttributes fixedFields;
        ball::UserFields       customFields;
//
        const int NUM_MESSAGES = 3;
        for (int n = 0; n < NUM_MESSAGES; ++n) {
            fixedFields.setTimestamp(bdlt::CurrentTime::utc());
//
            bsl::shared_ptr<const ball::Record> handle;
            handle.createInplace(bslma::Default::allocator(),
                                 fixedFields,
                                 customFields);
            adapter->publish(handle,
                             ball::Context(ball::Transmission::e_TRIGGER,
                                           n,
                                           NUM_MESSAGES));
        }
        if (verbose) {
            bsl::cout << out.str() << bsl::endl;
        }
        return 0;
    }
void MyPlugin2StartupShutdownServiceImpl::Startup()
{

	CAlert::InformationAlert("Start up servies started");

	InterfacePtr<IObserver> myObserver(GetExecutionContextSession(), IID_IMYOBSERVER);
	
	if (myObserver != nil)
	{
		myObserver->AutoAttach();
		CAlert::InformationAlert("Auto attached called");
	}
	else {
		CAlert::InformationAlert("nill!!!!!");
	}
	
	InterfacePtr<IObserver> mySelectionObserver(GetExecutionContextSession(), IID_IMYSELECTIONOBSERVER);

	if (mySelectionObserver != nil)
	{
		CAlert::InformationAlert("Auto attached called for active selection");
		mySelectionObserver->AutoAttach();
	
	}
	else {
		CAlert::InformationAlert("nill!!!!!");

	}

}