Home
Developer Resources
QNX RTOS v4
QNX RTOS v4 Knowledge Base

QNX RTOS v4 Knowledge Base

Foundry27
Foundry27
QNX RTOS v4 project
Resources

QNX RTOS v4 Knowledge Base

Title Info about how different PtTty resources play together
Ref. No. QNX.000009844
Category(ies) Development
Issue Can you provide us with more info in how different PtTty resources play together?


Solution Some of PtTty's resources are not just data stored in the widget, they are 'action resources' that define an action to be performed when resource is set.
This includes all the resources flagged as write-only. Some of those actions are order-dependant (e.g. you have to open device by setting Pt_ARG_TTY_FD, Pt_ARG_TTY_PATH, or Pt_ARG_TTY_PSEUDO) before you can spawn a program on the device (by setting Pt_ARG_TTY_CMD or Pt_ARG_TTY_ARGV).

The following resources are order-dependant even though they are not 'action resources':

x09Pt_ARG_TERM_PROTOCOL
x09Pt_ARE_TTY_FDSETx09
x09Pt_ARG_TTY_FLAGS (Pt_TTY_SETENV and Pt_TTY_ARGV0)
x09Pt_ARG_TTY_SPAWN_OPTIONS
Since the widget looks at the current values of those resources when spawning the command, changing their values after a command has been spawned does not affect the command that's already running. Make sure that those resources have correct values *before* you set Pt_ARG_TTY_CMD or Pt_ARG_TTY_ARGV.

Here some simple code examples:
/*this code assumes theat most resources, including Pt_ARG_TTY_PSEUDO, have been set up already(probably from PhAB)*/

int run_command(PtWidget_t *tty, char **argv){
x09PtArg_t arg;
/*Make sure that you have a tty*/
x09PtSetArg(&arg, Pt_ARG_TTY_MFD, 0, 0);
x09PgGetResources(tty, 1, &arg);
x09if (arg.value == -1){
x09x09PtTerminalPuts(tty, "Cannot find a free pseudo tty");
x09x09return -1;
x09}
/*run a command*/
x09PtSetArg(&arg, Pt_ARG_TTY_ARGV, argv, 0);
x09PtSetResources(tty, 1, &arg);

/*check if it succeeded*/
x09PtSetArg(&arg, Pt_ARG_TTY_PID, 0, 0);
x09PtGetResources(tty, 1, &arg);
x09if(arg.value == 0) {
x09x09PtSetArg(&arg, Pt_ARG_TTY_FD, -1, 0) /*close the pty*/
x09x09PtSetResources(tty, 1, &arg);
x09x09PtTerminalPuts(tty, "Cannot spawn the program");
x09x09return -1;
x09}
x09return 0;
}