This attribute associates a local data type that your application code uses with a data type defined in the IDL file. Use of the represent_as attribute means that during marshalling and unmarshalling, conversions occur between the data type used by the application code, and the data type specified in the IDL.
The represent_as attribute has the following syntax. (See the example at the end of this topic.)
typedef [represent_as (local_type_name)] net_type_name;
The local_type_name is the local data type that that the application uses. You can define it in the IDL file or in an application header file. If you do not define it in the IDL file, use the include statement in the ACF to make its definition available to the stubs.
The net_type_name is the data type that is defined in the IDL file.
The represent_as attribute can appear at most once in a typedef declaration in an ACF.
If you use the represent_as attribute, you must write routines that perform the conversions between the local and network types, and routines that release the memory storage used to hold the converted data. The conversion routines are part of your application code.
The suffix for the routine names, the function of each, and where they are used (client or server) appear in the following list:
· _from_local( ): Allocates storage instance of the network type and converts from the local type to the network type (used for client and server).
· _to_local( ): Converts from the network type to the local type (used for client and server).
· _free_inst( ): Frees storage instance used for the network type (used by client and server).
· _free_local( ): Frees storage used by the server for the local type (used in server). This routine frees any object pointed to by its argument, but does not attempt to free the argument itself.
Suppose that the represent_as attribute is applied to either the type of a parameter or to a component of a parameter and that the parameter has the out or in,out attribute. Then, the _free_local( ) routine will be called automatically for the data item that has the type to which the represent_as attribute was applied.
Suppose that the represent_as attribute is applied to the type of a parameter and that the parameter has only the in attribute. Then, the _free_local( )routine will be called automatically.
Finally, suppose that the represent_as attribute is applied to the type of a component of a parameter and that the parameter has only the in attribute. Then, the _free_local( ) routine will not be called automatically for the component; the manager application code must release any resources that the component uses, possibly by explicitly calling the _free_local( ) routine.
Append the suffix of the routine name to the net_type_name. The syntax for these routines is as follows:
void net_type_name _from_local (
(local_type_name *),
(net_type_name **))
void net_type_name _to_local (
(net_type_name *),
(local_type_name *))
void net_type_name _free_inst ((net_type_name *))
void net_type_name _free_local
((local_type_name *))
Example Using the represent_as Attribute
ACF
[auto_handle] interface phonedir
{
/*
* You must specify an included file that contains the
* definition of my_dir_t.
*/
include "user_types";
/*
* The application code wants to pass data type my_dir_t
* rather than dir_t. The [represent_as] clause allows
* this, and you must supply routines to convert dir_t
* to/from my_dir_t.
*/
typedef [represent_as(my_dir_t)] dir_t;
}
IDL File
[uuid(06a12100-2d26-11c9-aa24-08002b0ecef1)]
interface phonedir
{
typedef struct
{
short int area_code;
long int phone_num;
char last_name[20];
char first_name[15];
char city[20];
} dir_t;
void add ([in] dir_t *info);
void lookup ([in] char city[20],
[in] char last_name[20],
[in] char first_name[15],
[out] dir_t *info);
void delete ([in] dir_t *info);
}