> 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/other-pages/ctbcafcli.md).

# CTBCAFCli

The class *CTBCAFCli* provides a command-line interface that's more convenient that a single shell prompt, by allowing the application to display multiple pages of information, view the application log, and enter commands.

It also allows the application to be "remotely controlled" using the tbx\_cli\_tools\_remote application.

This module should be initialized through the *GlobalSetParams* function. Parameters for this module are contained in class *CTBCAFCliParams*

Please refer to documentation in the C++ header files for class *CTBCAFCliParams* to know more about available parameters.

An application that initializes this class has add one or more "Pages" (classes based on *ITBCAFCliPage*). The base class 'ITBCAFCliPage' has a couple of functions that need to be implemented:

* *Display*: Called every time the page needs to be refreshed on the screen. Application can present any relevant information on that page. Remaining space will automatically be used to show the log file.
* *HandleChoice*: Called when user pressed a key on the keyboard. Application can attach any behavior to any key. Some behaviors may prompt user for parameters (see example code below).
* *ValidateUserInput*: Called when it's required to prompt user for values after a command key has been pressed. This callback asks the application to validate the user input.
* *ApplyUserInput*: Called when the user finished entering the prompted values, and command is ready to be executed. Application should execute the command according to passed user input values.
* *GetTitle*: The application should return the title that it wants the page to appear with
* *IsEnabled*: The application should return whether current page should be visible or not
* *SetEnabled*: Called to enable the current page
* *GetHelp*: The application should return the help string to use with current page.

### Example usage

```
class CTBMyCliPage : public ITBCAFCliPage
{
// See sample code packages for example code using ITBCAFCliPage
};

class MyApplication
{
// your class definition

// Smart pointer to a CLI Page
CTBCAFPtr< CTBMyCliPage >		mptrMyCliPage;
};

TBX_RESULT MyApplication::Init()
{
TBX_RESULT			Result = TBX_RESULT_OK;
CTBCAFGlobalsParams	CafGlobalParams;
CTBCAFCliParams		CafCliParams;

// Set the parameters you want
CafCliParams.mfRemoteControllable	= TBX_TRUE;	// Make current application controllable through tbx_cli_tools_remote
CafCliParams.mfRunInServiceMode		= TBX_TRUE;	// Prevents CAFCli to use stdin or stdout
// (other parameters are generally left to default values)

CafGlobalParams.mpCliParams			= &CafCliParams;
// CafGlobalParams.mpCommParams		= [your paramters...]
// CafGlobalParams.mpLogParams		= [your paramters...]
// etc...

Result = TBCAF::GlobalSetParam( &CafGlobalParams );

if( TBX_RESULT_SUCCESS( Result ) )
{
// Allocate a new CTBCAFCli page
mptrMyCliPage = tbnew CTBMyCliPage();
}

if( mptrMyCliPage != NULL )
{
// Register cli page
Result = CTBCAFCli::AddPage( mptrMyCliPage );
}

return Result;
}

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

// Detach and free the page
if( mptrMyCliPage != NULL )
{
// Unregister cli page
CTBCAFCli::RemovePage( mptrMyCliPage );
}
mptrMyCliPage = NULL;

// Terminate all CAF modules
Result = TBCAF::GlobalSetParam( &EmptyGlobalParams );

return Result;
}
```


---

# 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/other-pages/ctbcafcli.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.
