> For the complete documentation index, see [llms.txt](https://prosbcdocs.telcobridges.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://prosbcdocs.telcobridges.com/telecom-references/apis-and-integration/ctbcafservicecmmgmtclient.md).

# CTBCAFServiceCmMgmtClient

The class *CTBCAFServiceCmMgmtClient* is used by applications that want to be informed of the current active configuration, and active database connection string.

An application that initializes this class has to provide a callback to interface *ITBCAFServiceCmMgmtClient*. This interface provides 3 functions that the application must implement:

* *OnValidateConfig*: Tells the application to validate the given configuration. This is already handled by standard, Toolpack applications so it's not required to do anything here.
* *OnReloadConfig*: Tells the application that the configuration has been modified (or active configuration changed), and the application must reload any information from the database that it previously loaded and kept locally
* *OnDbMaintenance*: This function is called to indicate to the application that the database is in maintenance mode (or unavailable) and should not be accessed. A call to *OnReloadConfig* will indicate when the database is ready again.

### Example usage

```
class MyApplication : public ITBCAFServiceCmMgmtClient
{
// your class definition

// Functions inherited from ITBCAFServiceCmMgmtClient
virtual TBX_VOID OnValidateConfig( TBX_UINT32 in_un32ConfigurationId, TBX_UINT32 in_un32ApplicationId, CTBCAFString in_strName );
virtual TBX_VOID OnReloadConfig( TBX_UINT32 in_un32ConfigurationId, CTBCAFString in_strName, CTBCAFString in_strDbConnString );
virtual TBX_VOID OnDbMaintenance();

PITBCAFDb						mpConfigDb;
TBX_UINT32						mun32ConfigurationId;
TBX_BOOL						mfDbMaintenance;
};

TBX_RESULT MyApplication::Init()
{
TBX_RESULT			Result = TBX_RESULT_OK;

// Database access object will be initialized later (once we know the connection string)
mpConfigDb		= NULL;
mfDbMaintenance	= TBX_TRUE;

// Initialize the CM client
Result = CTBCAFServiceCmMgmtClient::Init(this);

return Result;
}

TBX_RESULT MyApplication::UnInit()
{
TBX_RESULT			Result = TBX_RESULT_OK;

// Terminate CM client
Result = CTBCAFServiceCmMgmtClient::Uninit();

// Destroy the database access object
delete mpConfigDb;
mpConfigDb = NULL;

return Result;
}

TBX_VOID MyApplication::OnValidateConfig
(
IN		TBX_UINT32	 					in_un32ConfigurationId,
IN		TBX_UINT32	 					in_un32ApplicationId,
IN		CTBCAFString 					in_strName
)
{
// This application has nothing to validate in the database configuration
TBX_RESULT			ValidateResult	= TBX_RESULT_OK;
CTBCAFString		strValidateResult( "MyApplication: Ok (nothing to validate)" );
CTBCAFServiceCmMgmtClient::SendReloadDone( ValidateResult, strValidateResult.c_str() );
}

TBX_VOID MyApplication::OnReloadConfig
(
IN		TBX_UINT32	 					in_un32ConfigurationId,
IN		CTBCAFString 					in_strName,
IN		CTBCAFString 					in_strDbConnString
)
{
TBX_RESULT			Result	= TBX_RESULT_OK;
CTBCAFString		strReloadResult( "MyApplication: configuration reloaded successfully" );

CAFCODE( MyApplication::OnReloadConfig )
{
// Remember the current active configuration id
mun32ConfigurationId = in_un32ConfigurationId;

// Update the database connection string
if( mpConfigDb )
{
// Close current database connection.
mpConfigDb->Close();
mpConfigDb->SetConnectString(in_strDbConnString);
}
else
{
mpConfigDb = tbnew CTBCAFDb( in_strDbConnString.c_str() );
if( !mpConfigDb )
{
strReloadResult.Format( "Failed to allocate mpConfigDb" );
TBX_EXIT_ERROR( TBX_RESULT_OUT_OF_MEMORY, 0, strReloadResult.c_str() );
}

Result = mpConfigDb->SetOptions(ITBCAFDb::DB_OPTION_AUTO_RECONNECT);
if( TBX_RESULT_FAILURE( Result ) )
{
strReloadResult.Format( "Failed SetOptions (Result 0x%08X)", Result );
TBX_EXIT_ERROR( Result, 0, strReloadResult.c_str() );
}
}

// Re-open using the new connection string
if( mpConfigDb )
{
Result = mpConfigDb->Open();
if( TBX_RESULT_FAILURE( Result ) )
{
strReloadResult.Format( "Unable to open database (Result 0x%08X): %s", Result, mpConfigDb->GetLastError().c_str() );
TBX_EXIT_ERROR( Result, 0, strReloadResult.c_str() );
}
}

// We are no more in maintenance
mfDbMaintenance = TBX_FALSE;

// Reload whatever information required by this application from mpConfigDb

TBX_EXIT_SUCCESS( TBX_RESULT_OK );
}

/*---------------------------------------------------------------------------------------------------------------------------
|  Exception handling section
```

* \--------------------------------------------------------------------------------------------------------------------------\*/ CAF\_EXCEPTION\_HANDLING

  /\*--------------------------------------------------------------------------------------------------------------------------- | Error handling section
* \--------------------------------------------------------------------------------------------------------------------------\*/ CAF\_ERROR\_HANDLING( CAF\_VERBOSE ) { if( mpConfigDb && mpConfigDb->IsOpened() ) { mpConfigDb->Close(); } }

  /\*--------------------------------------------------------------------------------------------------------------------------- | Cleanup section
* \--------------------------------------------------------------------------------------------------------------------------\*/ CAF\_CLEANUP { // Reload from the database any information required by this application CTBCAFServiceCmMgmtClient::SendReloadDone( Result, strReloadResult.c\_str() ); }

  RETURN\_VOID; }

  TBX\_VOID MyApplication::OnDbMaintenance() { // Remember that we are in DB maintenance mfDbMaintenance = TBX\_TRUE; }


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://prosbcdocs.telcobridges.com/telecom-references/apis-and-integration/ctbcafservicecmmgmtclient.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
