• About TV's server
  • New in version 3.20
  • New in version 3.10
  • About the source code
  • About protocols/plugins
  • TV's server API
  • Protocol Initialisation
  • Protocol binding
  • Protocol Listening and handling
  • Protocol data storage
  • Control panel
  • Multi column list
  • Time and date
  • Http protocol functions
  • Unimplemented and/or replaced functions
  • TV's server API

    index About TV's server API system
    TV's server doesn't use regular import and export tables, instead it exchanges structures with pointer to the functions. This is done because regular import and export tables use more memory (since each function contains a string as identifier), so I choose to do the same with less. Plugins written in C still need to use the regular export table to export the __asm_exchange_tables function. This function will be called right afther the plugin is loaded in memory and has one parameter, a pointer to function __get_export_table that can be used to receive the pointers to the functions TV's server is providing. The plugin should also call the __asm_set_export_table function to set it's export table containing the functions it's providing to TV's server.

    Exporting __asm_exchange_tables and assembler
    Plugins written in assembler can choose to export __asm_exchange_tables like C-plugins (using the default export-table) or can choose the less memory consuming way. TV's server will search for the first section containing code and will compair the first 16 bytes in this section with the string "TV's server 3.00" (no zero-terminate byte). If the string matches it expect the next 4/8 (x86/x64) bytes to be a pointer to the __asm_exchange_tables function. Below there is an example how to implement.
    section '.text' code data readable writeable executable
    db "TV's server 3.00"
    dq __asm_exchange_tables
    

    Get/set export table example
    This example will show you how to exchange the export tables.
    #include <stdio.h>
    #include <stdlib.h>
    #include "tvsserver_base.h"
    
    APIImportTable importTable;
    
    struct Export_Table  my_export_table = 
    {
    	0,
    	sizeof(Export_Table)-8,
    	(GetProtocolNames*) _GetProtocolNames,
    	(StartProtocol*) _StartProtocol,\
    	(BindToProtocolCallBack*) _BindToProtocolCallBack,\
    	(StartListening*) _StartListening,\
    	(HandleConnection*) _HandleConnection,\
    	(RecvData*) _RecvData,\
    	(SendData*) _SendData,\
    	(CloseClientSession*) _CloseClientSession,\
    	(GetClientSessionInfo*) 0,\
    	(PrepareCloseListenSession*) _PrepareCloseListenSession,\
    	(CloseListenSession*) _CloseListenSession
    };
    
    #include "tvs_redefine_api_names.h"
    
    void __stdcall __asm_exchange_tables(__get_export_table *get_export_table_internal, __get_export_table *get_export_table) {
    	importTable.size = sizeof(APIImportTable) - 8; //Fill in the size, minus the size and reserved member
    	get_export_table_func((APIImportTable*) (((char*)&importTable)+4)); //pass pointer to the size member and skip the reserved member
    	__asm_set_export_table((Export_Table*) (((char*)&my_export_table)+4)); //pass pointer to the size member and skip the reserved member
    }