Copyright © TIBCO Software Inc. All Rights Reserved
Copyright © TIBCO Software Inc. All Rights Reserved


Chapter 13 TIBCO Wrapper Utility : Source Code Changes

Source Code Changes
To use the TIBCO Wrapper, ensure that you link in the wrapper libraries under C++. In addition, you need to make the following source code changes.
Java Only
Adapters need only be certain that they are updating the application’s state by using the MHostInfo class. This is how the Win32 Service Control Manager (SCM) get notified that the application is running. State change notifications are required, otherwise the SCM will regard the service as non-functional. This may lead to unexpected behavior.
For example:
main () {
//** 0) create MApp
   app = new MyMApp(appProperties);
//** 1) create MHostInfo
   MHostInfo hostInfo = new MHostInfo(app);
//** 2) set hostInfo service state
   hostInfo.setAppState(MUserApplicationState.INITIALIZING);
//** 3) associating MHostInfo to MApp
   app.setHostInfo(hostInfo);
   app.start();
}
onInitialization {
    MHostInfo hostinfo = MyMApp.getHostInfo();
    hostInfo.setAppState (MUserApplicationState.RUNNING);
}
You should create MHostInfo the same place you create MAppProperties so that you can set the "Initializing" state before setting "Running" state inside onInitialization().
Make sure that the application state is set for failure and exit conditions. Before the adapter exits, the state should be set first to STOPPING and then to STOPPED. While there is some facility in the TIBCO Wrapper tool to detect or correct inconsistent state changes, the application itself is responsible for setting state back to the SCM correctly.
Note that the tool can be used in conjunction with existing Java adapters without modification, provided they are updating the application state as noted above. Otherwise, this code needs to be added before attempting to install the adapter as a Service.
C++ Only
Adapters need to rename their current main() to ApplicationMain() and call the LaunchWrapper() method while passing their ApplicationMain() method to the wrapper.
In addition, the service state for C++ applications must be set using the wrapper function SetServiceState() instead of relying on MApp::setHostInfo().
Wrapper Sample Code
This section shows a sample C++ application code fragment that integrates the wrapper.
void AppMain( int argc, char * argv )
{
SetServiceState( SVC_INITIALIZING );
// your adapter startup code goes here
// NOTE: typical adapters will set the service state
   // to RUNNING inside of MApp::onInitialization()
   // instead of here. An exception would be adapters
   // that pass Mfalse to MApp::start().
   //…
SetServiceState( SVC_RUNNING );
//…
}
 
void AppStop()
{
SetServiceState( SVC_STOPPING );
// your app shutdown code here…
// Note that it may be more appropriate to set state
// in MApp::onTermination().
SetServiceState( SVC_STOPPED );
}
 
void main( int argc, char * argv )
{
LaunchWrapper( argc, argv, &AppMain, &AppStop );
}

Copyright © TIBCO Software Inc. All Rights Reserved
Copyright © TIBCO Software Inc. All Rights Reserved