Truxton event type get name

From truxwiki.com
Jump to navigation Jump to search

This retrieves the name of the event type. This corresponds to the [Name] column of the [EventType] table.

Syntax

void truxton_event_type_get_name( uint64_t event_type_handle, char * destination_string, size_t maximum_size );

Parameters

event_type_handle

This handle comes from calling truxton_event_type_create().

destination_string

The string buffer where the name will go.

maximum_size

The size of the destination_string buffer. The maximum number of characters written to the buffer will be maximum_size minus one to leave room for the null terminator.

Sample

void create_event_type( void )
{
   uint64_t truxton = truxton_create();

   uint64_t event_type = truxton_event_type_create( truxton );

   truxton_event_type_set_id( event_type, 21212 );
   truxton_event_type_set_name( event_type, "FBI Action" );

   if ( truxton_event_type_save( event_type ) == 0 )
   {
      printf("Cannot save event type to the database.\n");
   }
   else
   {
      char type_name[ 128 ];

      uint64_t new_id = truxton_event_type_get_id( event_type );

      truxton_event_type_get_name( event_type, type_name, sizeof( type_name ) ); 
      printf( "Created %s event type as id %" PRIu64 "\n", type_name, new_id );
   }

   truxton_event_type_destroy( event_type );
   truxton_destroy( truxton );
}

The PRIu64 in the sample code above is a standard way of formatting a 64-bit unsigned integer in C. Over the years, different compilers on different operating systems used different format specifiers for things, these PRI macros, along with some tricky string concatenation the compilers perform for you, allow you to maintain a single code base without a bunch of macro magic.