IBM
Contents Index Previous Next



GCI C Code Reference


This section is a code description of GCI. It describes what each function does and why it is used. Some of the functions must be implemented by you in your adaptation. See section Completing the Adaptation.

Predefined Types

These are the GCI value types with their respective value set:

GciStatus = { GciNotOk, GciOk }

GciVerdict = { GciFail, GciInConc, GciPass, GciNone}

GciTimeUnit ={ Gcips, Gcins, Gcius, Gcims, Gcis, Gcimin }

GciTimerStatus = { GCIRUNNING, GCISTOPPED, GCIEXPIRED }

GciPCORole = { GciUT, GciLT }

GciPCOID = INTEGER

GciTimerID = INTEGER

GciPosition = <internal position value>

GciSnapshotStatus = { GciSnapshotEvent, GciSnapshotNoEvent, GciSnapshotNotOk }

These are structured GCI value types with their respective members:

The general communication address type
typedef struct GciAddress {
  int     type;        /* Address type 0 - 100 is 	  
                         reserved by IBM Rational */
  char*   buffer;      /* The address stored in a 
                          buffer */
} GciAddress;

The general time value
typedef struct GciTime {
  unsigned long time_val;
  GciTimeUnit   unit;
} GciTime;


Management Interface

The management interface consists of the functions necessary for initiating and managing test runs. They provide an API to the TTCN runtime behavior.

GciStatus GciInit()

Initiates the TTCN Runtime Behavior. Must be called before any test cases are started.

GciStatus GciExit()

Shuts down the TTCN Runtime Behavior system. Usually called last before closing a test session.

GciVerdict GciStartTestCase( const char* TCorTGName )

Calling this function with a test case name will start and run the given test case. The verdict returned is the verdict set by the test case.
If the function is called with a test group name, it will start and run the given test group. The verdict returned is the product of the verdicts set in the test cases or test groups contained in the given test group. The individual verdicts from the different test cases or test groups have to be extracted from the log. The verdict algorithm for test groups is defined as follows:
  1. The verdict is PASS if the verdict of every test case is PASS.
  2. The verdict is INCONC if the verdict of at least one test case is INCONC and all others are PASS.
  3. The verdict is FAIL if the verdict of at least one test case is FAIL.
    If the given name is not a valid test case nor test group, the function will return GciNotOk and log the following message:
    No such Test Case or Test Group as <name> to run!
    

GciVerdict GciStartTestComponent( char* TSName,
GciValue** args )

This function works just like GciStartTestCase but is used to start a parallel test component (PTC) when using concurrent TTCN. TSName is the name of the Test Step to run in the PTC.

GciTCList* GciGetTestCaseList()

This function returns a list of all test case names (including test cases in test groups).

GciTCList GciGetTestCaseGroupList()

This function returns a list of all test group names (including test groups in test groups). List of character strings.

GciValue* GciGetValue(char* TTCNObjectName)

This function returns the TTCN value object given the object's name. If the object name does not exist, the function will return NULL and log the following message:
GciGetValue: Could not find <name>! NULL returned

If the object name is a TTCN name, but not an object (variable, constant, etc...) the function will return NULL and log the following message:
GciGetValue: <name> not an instance! NULL returned

int GciGetNoOfTimers( )

Returns the number of timers in the system.

int GciGetTimer( int index )

Returns the identifier of the given timer index.

char* GciGetTimerName( int timer )

Returns the name of the given timer.

int GciGetTimerIndex( int desc )

Returns the index of the given timer descriptor.

int GciGetNoOfPCOs( )

Returns the number of PCOs in the system.

int GciGetPCO( int index )

Returns the descriptor of the given PCO index.

char* GciGetPCOName( int pco )

Returns the name of the given PCO.

int GciGetPCOIndex( int desc )

Returns the index of the given PCO descriptor.

int GciGetPCOType( pco )

Returns the type of a given PCO.

GciStatus GciGetPCORole( int pco, GciPCORole *role )

This function finds the role of PCO from its ID. Returns GciOk and assigns the role value to 'role' when successful. Returns GciNotOk when the function fails.

GciStatus GciClearAllPCOSAndCPS( void )

This function clear all PCOs and CPs queues. There is no need to call this function before starting a Test Case as the queues are cleared automatically.

int GciGetNoOfComponents( GciConf conf )

Returns the number of components in the given configuration.

GciComponent* GciGetComponent( GciConf conf, int index )

Returns the indexed component in the given configuration.

char* GciGetComponentName( GciComponent* conp )

Returns the name of the given component.

int GciGetComponentType( GciComponent* conp )

Returns the type of the given component (GciMTC or GciPTC).

int GciGetComponentDescriptor( GciComponent* conp )

Returns the descriptor of the given component.

char** GciGetComponentCPs( GciComponent* conp )

Returns the CPs used by the given component.

char** GciGetComponentPCOs( GciComponent* conp )

Returns the PCOs used by the given component.

Behavior Interface

The behavior interface consists of the functions used to notify the TTCN Runtime Behavior of events in the IUT. The functions are a formalism of what the TTCN Runtime Behavior needs to know about the status of the IUT. The functions are implemented in the TTCN Runtime Behavior and must be used in Snapshot.

GciStatus GciTimeout( int timerd )

This function will change the status of the internal timer indexed by the timer descriptor timerd. The timer will be marked as timed out.

GciStatus GciReceive( int pcod, GciValue* value )

This function will insert the received object into the internal PCO queue indexed by the PCO descriptor pcod.

Operational Interface

The operational interface consists of the functions necessary for the TTCN Runtime Behavior to communicate with the IUT, i.e. the dependencies on the protocol and test environment. It implements functionality for Send, Snapshot, StartTimer, etc. The TTCN Runtime Behavior requires that the functions are defined in the adaptation.

GciValue* GciReadTSPar( char* name, char* pRef )

The user has to implement how to read the test suite parameters. This code will be called one time for each test suite parameter in the system. Here name is the name of the test suite parameter and pRef is the PICS/PIXIT field (ex. file). The value returned by this function must be a pointer to a valid GciValue structure which can be successfully used by the TTCN runtime behavior. If for any reason this could not be done, NULL should be returned.

GciStatus GciConfig( GciConf conf )

When using concurrent TTCN the user is responsible for creating the configurations to be used for a given test. The creation of those configurations is done in this function using a set of help functions in the management interface to traverse the information.

GciStatus GciSnapshot()

This is a very important function that the user has to implement. This function is called from the run-time behavior when it needs input from the test environment (timers and/or PCO's).
  • Communication lines (PCOs) must be checked. If something has been received, we must decode the message, build a receive object and insert the object into the correct, internal PCO queue by using the GciReceive function with appropriate PCO descriptor. The GCI Value Interface is used to build the object(s).
  • Timers must be checked and their status must be reported to the TTCN run-time system. If the user uses the simple adaptation template he/she must self keep track of time and use GciTimeout to mark a timer as timed out. If the user uses the timers adaptation template he/she can use the AdSetTime function (see below) to have this work done automatically.

GciSnapshotStatus GciPollingSnapshot()

This function is similar to the GciSnapshot function.
The main difference is that GciPollingSnapshot should poll the PCOs and Timers in the system, check the termination of the different test components, but should not stop and wait for any event above. If no events are done, GciPollingSnapshot should return, as opposed to GciSnapshot, that can be designed to stop and wait for an event to occur.
There is also a difference in the return value, GciPollingSnapshot will show if any event has occured or not, compared to GciSnapshot, where the return means that any event occured.
Return Value: GciSnapshotStatus
  • GciSnapshotEvent, if everything in snapshot went fine and any event occured.
  • GciSnapshotNoEvent, if everything in snapshot went fine and no event occured.
  • GciSnapshotNotOk, if something catastrophic occured while doing the snapshot.
    For backward compatibility with previous versions of adaptation, this function does not have to be implemented. For use with previous versions a dummy implementation exists in the TTCN static library which prevent linker errors.

GciStatus GciSend(int pcod, GciValue* value)

The user is responsible for implementing the send functionality. This involves identifying a given PCO and encoding the value before sending the message on that PCO.

GciStatus GciStartTimer(int timerd, long duration,
int unit)

To start a timer the TTCN runtime behavior will call this function. Note that timer duration value is optional in TTCN but is always present here.

GciStatus GciCancelTimer(int timerd)

This function is called to stop the given timer. It should have the effect that the appropriate timer representation in the adaptation is stopped.

long GciReadTimer(int timerd)

This function is called when a timer is read. It must return the current timer value.

GciStatus GciCreate(int ptc, char* tree, GciValue* args)

This functions is called when a PTC is to be created to run a given dynamic behavior with the given arguments (concurrent TTCN).

GciValue* <TS_Op>( <Arguments> )

Every test suite operation must have this function defined. The name shall be the same as in the ATS and arguments must match the parameters in the ATS.

GciStatus GciImplicitSend( GciValue* value )

This function is called by the run-time behavior when an Implicit Send Event occurs in the test suite. It is up to the adaptation writer to define its exact implementation.

GciStatus GciLog(int logId, char* LogString)

The user has to implement parts of the logging facility. As the GCI document describes, all log identifiers are already implemented. User may change the logging for any event like it is desired. The log identifiers (identifies the type of log message) in this function should NOT be changed as they follow the values listed in the GCI document. The TTCN Runtime Behavior uses this function with these identifiers for logging.

logId Description logString must contain:
Msg

General message

Any information

StartTC

Start test case

The name of the test case

StopTC

Stop test case

The name of the test case

Verdict

Final verdict set

The verdict set

PVerdict

Prel. verdict set

The preliminary verdict set

Match

Line tried matches

Line number

NoMatch

Line tried does not match

Line number

SendE

Send Event

Line number
The PCO name
The type of message sent
Constraint name and sent value

RecE

Receive Event1

Line number
The PCO name
The type of message received
Constraint name and received value

OtherE

Otherwise Event

Line number
The PCO name
The type of message received
Received value

TimeoutE

Timeout Event

Line number
The timer name

Assign

Assignment

Line number
The left hand side
The right hand side (textually)

StartT

Start timer

Line number
The timer name
The timer duration

CancelT

Cancel timer

Line number
The timer name

ReadT

Read timer

Line number
The timer name
The timer value

Attach

Attachment: enter or exit test step

Line number
Name of the attached Test Step
Event type:
Enter Test Step/Exit Test Step
Test Step actual parameters

ImplSend

Implicit send

The sent value

Timeout

Timeout2

The timer descriptor number

Error

The error message

Error message text

Create

CREATE construct has been executed

Line number

Component name

Test Step name

Test Step actual parameters

Done

DONE Event

Line number

Component name(s)

Activate

Activate Event

Line number

List of Defaults

MatchFailed

A received line does not match.

Expected constraint name

When logging is verbose, also constraint value and received value

BeginMatchType

When logging is verbose: Check that types and names have the constraint and incoming value or their corresponded parts, before trying to match them.

Constraint and incoming value: name, type name, base type name, class and tag.

SuccMatchType

When logging is verbose: The constraint and incoming value or their corresponded parts have been matched successfully.

Constraint name and type.

FailMatchType

When logging is verbose: The constraint and incoming value or their corresponded parts have not been matched.

Constraint name and type.

SuccMatchValue

When logging is verbose: The constraint and incoming value, or their corresponding parts, that were looked upon as simple values (the match process has not looked inside), have been matched successfully.

Constraint and incoming value

GciLogFailMatchV
alue

When logging is verbose: The constraint and incoming value, or their corresponding parts, that were looked upon as simple values (the match process has not looked inside), have not been matched

Constraint and incoming value

FailAssignSignal

Generated by the SDL and TTCN Integrated Simulator when impossible to assign the incoming signal to the GCI value. The type on SDL and TTCN side thus has different descriptions

Part of incoming value that was assigned successfully to GCI value.

StartPTC

PTC has started

Test Step name

StopPTC

PTC has finished

Test Step name

CallQueue

When log option "Show executable path" is on, show Test Steps stack when new Test Step is started

Test Steps stack

1

Logging that a receive line matches.

2

Note this is low level logging done when the Test Adaptation writer calls GciTimeout

Value Interface

The interface to values is a simple API in which the user is allowed to build and access GciValues in an ordered way. The actual values used are not specified, only the methods that can be used on them are included. This way will allow vendors to have their own value representation within their TTCN Runtime Behavior and still conform to GCI.

Base Types/Values

These functions are used to transform actual values into the GCI representation. The interface is on base types only, so TTCN simple types are not visible in the interface.

GciValue* GciMkINTEGER( long num )
long GciGetINTEGER( GciValue* value )

These functions are used for INTEGER values and any simple type values of the base type INTEGER. These functions may be used for INTEGER values in the range of -2^31..2^31-1. Compare these functions with the GciMkBigINTEGER and GciGetBigINTEGER which are more universal and can be used for any unlimited INTEGER value.

Note:

The TTCN Suite RTS supports INTEGER values in the range of:
-2^32-1..2^32-1

GciValue* GciMkBigINTEGER(const char *value)
char* GciGetBigINTEGER(GciValue* value, char *buffer)

These functions should be used instead of GciMkINTEGER and GciGetINTEGER when the value is unknown or larger than what is allowed for the type long. The buffer should be large enough to store the given value (see the function GciGetBigINTEGERMaxSize).
The GciMkBigINTEGER function returns a new created value. The function will return NULL if there is an error.
A successful call of GciGetBigINTEGER will return a buffer. The function will return NULL if there is an error.

int GciGetBigINTEGERMaxSize(GciValue *value)

Returns the size of a buffer that is large enough for retrieving the character value of a value of the type INTEGER or ENUMERATED.

Bool GciIsBigINTEGERFitsLong(GciValue *value)

Returns GcTRUE when a value of the type INTEGER or ENUMERATED can be retrieved in a value of the type long (using the GciGetINTEGER function). The function will otherwise return GcFALSE.

GciValue* GciMkBOOLEAN( int bool )
int GciGetBOOLEAN( GciValue* value)

Used for Boolean values and for any simple type values with the base type Boolean.

GciValue* GciMkREAL(int mantissa, int base, int exponent)
GciReal GciGetREAL( GciValue* value)

Used for values of type Real and for any simple type values with the base type Real.

GciValue* GciMkBIT_STRING( const char* str )
char* GciGetBIT_STRING( GciValue* value)

Used for bit string values and for any simple type values with the base type bit string.

GciValue* GciMkHEXSTRING( const char* str )
char* GciGetHEXSTRING( GciValue* value)

Used for hex string values and for any simple type values with the base type hex string.

GciValue* GciMkOCTET_STRING( const char* str )
char* GciGetOCTET_STRING( GciValue* value)

Used for octet string values and for any simple type values with the base type octet string.

GciValue* GciMkNumericString( const char* str )
char* GciGetNumericString( GciValue* value)

Used for values numerical strings and for any simple type values with the base type numerical string.

GciValue* GciMkPrintableString( const char* str )
char* GciGetPrintableString( GciValue* value)

Used for Printable string values and for any simple type values with the base type Printable string.

GciValue* GciMkTeletexString( const char* str )
char* GciGetTeletexString( GciValue* value)

Used for Teletex string values and for any simple type values with the base type Teletex string.

GciValue* GciMkVideotexString( const char* str )
char* GciGetVideotexString( GciValue* value)

Used for Videotex string values and for any simple type values with the base type Videotex string.

GciValue* GciMkVisibleString( const char* str )
char* GciGetVisibleString( GciValue* value)

Used for Visible string values and for any simple type values with the base type Visible string.

GciValue* GciMkIA5String( const char* str )
char* GciGetIA5String( GciValue* value)

Used for IA5string values and for any simple type values with the base type IA5string.

GciValue* GciMkT61String( const char* str )
char* GciGetT61String( GciValue* value)

Used for T61string values and for any simple type values with the base type T61string.

GciValue* GciMkISO646String( const char* str )
char* GciGetISO646String( GciValue* value)

Used for ISO646string values and for any simple type values with the base type ISO646string.

GciValue* GciMkGraphicalString( const char* str )
char* GciGetGraphicalString( GciValue* value)

Used for Graphical string values and for any simple type values with the base type Graphical string.

GciValue* GciMkGeneralString( const char* str )
char* GciGetGeneralString( GciValue* value)

Used for General string values and for any simple type values with the base type General string.

GciValue* GciMkENUMERATED( int value )
int GciGetENUMERATED( GciValue* value)

Used for Enumerated values and for any simple type values of the base type Enumerated. These functions may be used with integer values of ENUMERATED values that are in the range of:
-2^31..2^31-1
The functions GciMkBigENUMERATED and GciGetBigENUMERATED are more universal and may be used for any unlimited ENUMERATED values.

Note:

The TTCN Suite RTS supports ENUMERATED values in the range of:
-2^32-1..2^32-1

GciValue* GciMkBigENUMERATED(const char *enumeration)
char* GciGetBigENUMERATED(GciValue* enumerated_object, char *buffer)

These functions should be used instead of GciMkENUMERATED and GciGetENUMERATED when the value is unknown or larger than what is allowed for the type int. The buffer should be large enough to store the value (see the function GciGetBigINTEGERMaxSize).
The function GciMkBigENUMERATED returns a new created value. The function will return NULL if there is an error.
The function GciGetBigENUMERATED function returns a buffer when successful. The function will return NULL if there is an error.

GciValue* GciMkCHOICE(const char* name, GciValue* value)
GciValue* GciGetCHOICE( GciValue* value)
char* GciGetCHOICEName( GciValue* value)

Used for Choice values and for any simple type values with base type Choice.

GciValue* GciMkOBJECT_IDENTIFIER()
int GciOBJECT_IDENTIFIERSize( GciValue* value)
GciValue* GciAddOBJECT_IDENTIFIERComponent(
GciValue* value, int comp)
int GciGetOBJECT_IDENTIFIERComponent( GciValue* value,
int index)

Used for Object identifier values and for any simple type values with base type Object identifier.

GciValue* GciMkObjectDescriptor( const char* str )
char* GciGetObjectDescriptor( GciValue* value)

Used for ObjectDescriptor values and for any simple type values with base type ObjectDescriptor.

GciValue* GciMkNULL( )
int GciGetNULL( GciValue* value)

Used for Null type values and for any simple type values with base type Null type.

GciValue* GciMkANY( GciValue* value )
GciValue* GciGetANY( GciValue* value)

Used for ANY values and for any simple type values with base type ANY.

GciValue* GciMkR_TYPE( int value )
int GciGetR_TYPE( GciValue* value)

Used for R_Type values and for any simple type values with base type R_Type.

GciValue* GciMkPDU( GciValue* value )
GciValue* GciGetPDU( GciValue* value)

Used for PDU values and for any simple type values with base type PDU.

Base Functions

int GciGetType( GciValue* val )

Shall return the type of a value. The type is represented as the number used to identify global objects, see Identifying Global Objects in TTCN/ASN.1. The function is valid for all values, but some values may be untyped in which case the function returns -1. These integer values used to identify all predefined and user-defined types are listed in the "type_gen.h" file generated by the TTCN C Code Generator. There is a function to get the symbolic type name from the integer value (const char* GciGetTypeNameString(int TypeID)). A reverse function exists to get the integer type value from the symbolic name (int GciGetTypeDescriptor(const char *type_name)).

GciValue* GciSetType( int type, GciValue* val )

Shall set the type of a value. The type is represented as the number used to identify global objects, see Identifying Global Objects in TTCN/ASN.1. Valid for all values. Returns the input value with type set.

int GciGetBaseType ( GciValue* val )

Shall return the base type (always one of the predefined types) of a value. The type is represented as the number used to identify global objects, see Identifying Global Objects in TTCN/ASN.1.

const char* GciGetTypeNameString(int TypeID)

Shall return the symbolic name of a type with integer value TypeID.

int GciGetTypeDescriptor(const char *type_name)

Shall return the integer value for the type with the symbolic name type_name.

Value Management

The functions are divided into two meta sets derived from ASN.1: The sequence and the sequence of, corresponding to struct and array in C. The choice type of ASN.1 is not represented as a meta class because all values in the GCI value representation can be typed and therefore is the choice value implicit in GCI.

The functions only works within their intended set (e.g. GciSetField(GciMkSEQUENCE(2), 1, GciMkINTEGER()) is well defined but GciSetField(GciMkSEQUENCEOF(), 0, GciMkINTEGER()) is not defined and certainly is unpredictable.

Sequence and Set Types/Values

GciValue* GciMkSEQUENCE( int size )

Creates a sequence value with size children.

GciValue* GciSetField( GciValue* seq, int index,
GciValue* fld )

Sets the field identified by index to the given value. Indices start at 1. The function is undefined for indices greater than the size of the sequence.

GciValue* GciGetField( GciValue* seq, int index )

Returns the field identified by index. Indices start at 1. The function is undefined for indices greater than the size of the sequence.

int GciSeqSize( GciValue* seq )

Returns the number of fields declared in the sequence seq.
Sequence of and Set of Types/Values

GciValue* GciMkSEQUENCEOF()

Creates a sequence of value.

GciValue* GciAddElem( GciValue* seqOf, GciValue* elem )

Adds the element elem to the end of sequence of seqOf.

GciValue* GciGetElem( GciValue* seqOf, int index )

Returns the element number index of the sequence of seqOf. Indices start at 0. The function is undefined for indices greater than current size.

int GciSeqOfSize( GciValue* seqOf )

Returns the current number of elements in seqOf.

Examples

This section contains examples of how the mapping between TTCN/ASN.1 and their GCI representation could be done. The examples use a conceptual model for encoding/decoding, no error handling is done and no attention is paid to the fact that some functions would use pointers because of allocation issues.

Global objects (PCOs and types) are identified with an unique number. This number is given a symbolic reference which is its TTCN name with a D for Descriptor appended to the end of it. The number for the PCO L is therefore referenced as LD.

Encoding/Decoding Examples

Each example consists of a table and the corresponding encode (and/or decode) functions. The examples focus on the value representation so the transfer syntax is simple: Each value is preceded by a header. The header contains the type of the value (as a number) and in some cases its length (element count, not size in bytes), in real ASN.1, the header would be built using tags. The header is written/read using primitives BufWriteType, BufWriteSeqOfSize, etc. They are not encode/decode primitives but rather buffer primitives.

An encode function is a function that translates the GCI value onto a buffer. A decode function is one that reads a value from a buffer and builds a value in the GCI representation. Encoding functions are called from SEND and decoding functions are called from SNAPSHOT. The buffer has type Buffer and could be anything behaving as a sequence of bytes. The primitives BufReadInt, BufReadBool are used to read and write GCI basic values.

ASN.1 SEQUENCE Type

Figure 273 : Example

Encode
void EncodeT1( Buffer buf, GciValue* v)
{
  BufWriteType( buf, GcT1D );
  BufWriteInt( buf, GciGetField( v, 1 ));
  BufWriteBool( buf, GciGetField( v, 2 ));
}
Decode
void DecodeT1( Buffer buf, GciValue** v)
{
  int i;

  if ( BufReadType( buf ) != GcT1D )
    Error();
  *v = GciMkSEQUENCE( 2 );
  GciSetType( GcT1D, *v );

  i = BufReadInt( buf );
  GciSetField( *v, 1 , GciMkINTEGER( i ) );

  i = BufReadBool( buf );
  GciSetField( *v, 2 , GciMkBOOLEAN( i ) );
}

ASN.1 SEQUENCE OF Type

Figure 274 : Example

Encode
void EncodeT2( Buffer buf, GciValue* v )
{
  int i;

  BufWriteType( buf, GcT2D );
  BufWriteSeqOfSize( buf, GciSeqOfSize( v ) );
  for (i = 1 ; i <= GciSeqOfSize( v ) ; i++ )
    {
      EncodeT1( buf, GciGetElem( v, i ) );
    }
Decode
void DecodeT2( Buffer buf, GciValue** v )
{
  int i, seqOfSize;
  GciValue* elem;

  if ( BufReadType( buf ) != GcT2D )
    Error();

  *v = GciMkSEQUENCEOF();
  GciSetType( GcT2D, *v );

  seqOfSize = BufReadSeqOfSize( buf );
  for ( i = 1 ; i <= seqOfSize ; i++ )
    {
      DecodeT1( buf, &elem );
      GciAddElem( *v, elem );
    }
}

ASN.1 CHOICE

Figure 275 : Example

Encode
void EncodeT3( Buffer buf, GciValue* v )
{
  const char *name = GciGetCHOICEName(v);
  GciValue *member = GciGetCHOICE(v);

  BufWriteType( buf, GcT3D );
  BufWriteString( buf, name );

  if(strcmp(name, "c1") == 0)
      EncodeT1( buf, v );
  else if(strcmp(name, "c2") == 0)
      EncodeT2( buf, v );
  else
      Error();
}
Decode
void DecodeT3( Buffer buf, GciValue** v )
{
  const char *name;
  GciValue *member;

  if ( BufReadType( buf ) != GcT3D )
    Error();
  name = BufReadString( buf );
  
  if(strcmp(name, "c1") == 0)
      DecodeT1( buf, &member );
  else if(strcmp(name, "c2") == 0)
      DecodeT2( buf, &member );
  else
      Error();

  *v = GciMkCHOICE((char *)name, member);
  GciSetType( GcT3D, *v );
  BufFreeString(name);
}

In-Line ASN.1 Type

Figure 276 : Example

Encode
void EncodeT4( Buffer buf, GciValue* v )
{
  GciValue* tmp;

  BufWriteType( buf, GcT4D );
  /* Encode first field */
  EncodeT1( buf, GciGetField( v, 1 ));
  /* Now encode inline type definition */
  tmp = GciGetField( v, 2 );
  BufWriteInt( buf, GciGetField( tmp, 1 ));
  EncodeT2( buf, GciGetField( tmp, 2 ));
}
Decode
void DecodeT4( Buffer buf, GciValue** v)
{
  int i;
  GciValue* tmp;
  GciValue* tmpseq;

  if ( BufReadType( buf ) != GcT4D )
    Error();

  *v = GciMkSEQUENCE( 2 );
  GciSetType( GcT4D, *v );

  DecodeT1( buf, &tmp );
  GciSetField( *v, 1, tmp );
  tmpseq = GciMkSEQUENCE( 2 );
  i = BufReadInt( buf );
  GciSetField( tmpseq, 1, GciMkINTEGER( i ) );
  DecodeT2( buf, &tmp );
  GciSetField( tmpseq, 2, tmp );
  GciSetField( *v, 2, tmpseq );
}

TTCN Examples

myQueue below is the Test Adaptation writers own representation of the PCO queue(s). In this example there is only one PCO, called L (Ld for its number). Note that the number Ld can be any number (most certainly not zero).

Snapshot Example

Snapshot must read the status of the IUT and tell this to the TTCN Runtime Behavior.

void GciSnapshot()
{
  GciValue* v;

  /* Check if anything has arrived,  */
  /* This would be a while statement */
  /* in a blocking context           */
  if ( ! myQueue[ 0 ].empty )
    {
      switch ( BufPeekType( myQueue[0].buf ))
        {
        case GcT1D:
          DecodeT1( myQueue[0].buf, &v );
          break;
        case GcT2D:
          DecodeT2( myQueue[0].buf, &v );
          break;
        default:
          Error();
        }

      GciReceive( GcLD, v );
    }

  /* Nothing has happened. */
}

Send Example

For the send example the following ASP table is used to show an API view of encode.

Figure 277 : Example

/* Two examples of send functionality */
GciStatus GciSend( int pcoDescr, GciValue* msg )
{
  if ( pcoDescr == GcPcoToSocketD )
    {
      /* Encode first */
      if ( GciGetType( msg ) == GcT1D )
        {
          EncodeT1( buf, msg );
          BufSocketSend( buf );
        }
    }
  else if ( pcoDescr == GcPcoToAPID )
    {
      if ( GciGetType( msg ) == GcTCONreqD )
        {
          Buffer pdu;
          EncodeT1( pdu, GciGetField( msg, 2 ));
          /* Call to lower layer */
          T_CONreq( GciGetField( msg, 1 ), pdu );
       }
    }

http://www.ibm.com/rational
Contents Index Previous Next