/*!-----------------------------------------------------------------------

    L u a _ v s i C o r e C l o s e

	@brief Close the VSI core environment.

    Lua Interface:

      Input arguments:  None

      Return values:  None

    Note that this call will undo everything that was set up by the "open"
    call.  However, it will not destroy the persistent data created while the
    core was in use.  Only the data allocated in the context of the virtual
    address space of the current process will be destroyed.

    After calling this function, any access to an item located in the core
    data store will result in a SEGV signal being generated.

    VSI C Interface:

        void vsi_core_close ( vsi_core_handle handle );

	@param[in] handle - The VSI data store handle.

	@return None

------------------------------------------------------------------------*/
static int Lua_vsiCoreClose ( lua_State* L )
{
    //
    //  Go close the VSI core data store.
    //
    vsi_core_close();

    //
    //  Mark the VSI core data store as "closed".
    //
    handle = 0;

    //
    //  Indicate that we are not returning anything to Lua.
    //
    return 0;
}
Esempio n. 2
0
/*!-----------------------------------------------------------------------

    m a i n

    @brief The main entry point for this compilation unit.

    This function will read and remove a single message from the shared memory segment
    as specified by the user.

    The "domain" will default to "CAN" if not specified by the caller and the
    "key" value will default to 0.

    Note that the "body" data will be read as 8 bytes of data and interpreted
    as a numeric value and as an ASCII string on output.

    @return  0 - This function completed without errors
    @return !0 - The error code that was encountered

------------------------------------------------------------------------*/
int main ( int argc, char* const argv[] )
{
    //
    //  The following locale settings will allow the use of the comma
    //  "thousands" separator format specifier to be used.  e.g. "10000"
    //  will print as "10,000" (using the %'u spec.).
    //
    setlocale ( LC_ALL, "");

    //
    //  Parse any command line options the user may have supplied.
    //
    signal_t signal     = 0;
    domain_t domain  = DOMAIN_CAN;
    int status            = 0;
    char ch               = 0;

    while ( ( ch = getopt ( argc, argv, "d:s:nh?" ) ) != -1 )
    {
        switch ( ch )
        {
          //
          //  Get the requested domain value.
          //
          case 'd':
            domain = atol ( optarg );
            LOG ( "Using domain value[%'d]\n", domain );
            break;

          //
          //  Get the requested key value.
          //
          case 's':
            signal = atol ( optarg );
            LOG ( "Using signal value[%'d]\n", signal );
            break;

          //
          //  Display the help message.
          //
          case 'h':
          case '?':
          default:
            usage ( argv[0] );
            exit ( 0 );
        }
    }
    //
    //  If the user supplied any arguments not parsed above, they are not
    //  valid arguments so complain and quit.
    //
    argc -= optind;
    if ( argc != 0 )
    {
        printf ( "Invalid parameters[s] encountered: %s\n", argv[argc] );
        usage ( argv[0] );
        exit (255);
    }
    //
    //  Open the shared memory file.
    //
    //  Note that if the shared memory segment does not already exist, this
    //  call will create it.
    //
    vsi_initialize ( false );

    //
    //  Go flush all messages with the given domain and key.
    //
    LOG ( "  Flushing domain: %'d\n  key...: %'d\n", domain, signal );

    status = vsi_core_flush_signal ( domain, signal );
    if ( status != 0 )
    {
        printf ( "----> Error %d[%s] returned\n", status, strerror(status) );
    }
    //
    //  Close our shared memory segment and exit.
    //
    vsi_core_close();

    //
    //  Return a good completion code to the caller.
    //
    return 0;
}
Esempio n. 3
0
/*!-----------------------------------------------------------------------

	m a i n

	@brief The main entry point for this compilation unit.

	This function will perform the dump of the shared memory segment signal
	lists according to the parameters that the user has specified.

	@return  0 - This function completed without errors
    @return !0 - The error code that was encountered

------------------------------------------------------------------------*/
int main ( int argc, char* const argv[] )
{
	unsigned long messagesToDump = 4;
	unsigned long listsToDump    = 4;
    unsigned int  domain         = 0;
    unsigned int  key            = 0;

	//
	//	The following locale settings will allow the use of the comma
	//	"thousands" separator format specifier to be used.  e.g. "10000"
	//	will print as "10,000" (using the %'u spec.).
	//
	setlocale ( LC_ALL, "");

    //
    //	Parse any command line options the user may have supplied.
    //
	char ch;

    while ( ( ch = getopt ( argc, argv, "ad:hk:l:m:?" ) ) != -1 )
    {
        switch ( ch )
        {
          case 'a':
            LOG ( "Dumping all -empty lists.\n" );
            listsToDump = 999999999;
            messagesToDump = 999999999;

            break;

		  //
		  //	Get the requested domain to dump.
		  //
		  case 'd':
		    domain = atol ( optarg );
			break;

		  //
		  //	Get the requested key to dump.
		  //
		  case 'k':
		    key = atol ( optarg );
			break;

		  //
		  //	Get the requested list count.
		  //
		  case 'l':
		    listsToDump = atol ( optarg );
			if ( listsToDump <= 0 )
			{
				LOG ( "Invalid list count[%lu] specified.\n", listsToDump );
				usage ( argv[0] );
				exit (255);
			}
			break;

		  //
		  //	Get the requested message count.
		  //
		  case 'm':
		    messagesToDump = atol ( optarg );
			if ( messagesToDump <= 0 )
			{
				LOG ( "Invalid message count[%lu] specified.\n", messagesToDump );
				usage ( argv[0] );
				exit (255);
			}
			break;

          //
          //    Display the help message.
          //
          case 'h':
          case '?':
          default:
            usage ( argv[0] );
            exit ( 0 );
        }
    }
    //
	//	If the user supplied any arguments other than the buffer size value,
	//	they are not valid arguments so complain and quit.
    //
	argc -= optind;
    if ( argc != 0 )
    {
        printf ( "Invalid parameters[s] encountered: %s\n", argv[argc] );
        usage ( argv[0] );
        exit (255);
    }
	//
	//	Open the shared memory file.
	//
	//	Note that if the shared memory segment does not already exist, this
	//	call will create it.
	//
	vsi_core_open ( false );

	//
	//	For each of the messages we were asked to dump...
	//
	LOG ( "Beginning dump of VSI core data store[%s]...\n",
	         SHARED_MEMORY_SEGMENT_NAME );
    //
    //  If the user did not specify a key, dump starting at the beginning
    //  of the signal list.
    //
    if ( key == 0 )
    {
        //
        //	Go dump all of the current signals.
        //
        dumpAllSignals ( messagesToDump );
    }
    //
    //  If the user did specify a key, find the signal list for that key and
    //  dump just that signal list.
    //
    else
    {
        signalList_t  desiredSignal;
        signalList_t* signalListFound;

        desiredSignal.domain = domain;
        desiredSignal.key    = key;

        //
		//  Get the signal list for this domain/key value.
		//
		signalListFound = btree_search ( &smControl->signals, &desiredSignal );

		//
		//  If the domain/key was not found, issue an error message.
		//
		if ( signalListFound == NULL )
        {
            printf ( "Error: No signal list defined for %d/%d\n", domain, key );
            return 255;
        }
        //
        //	If we found the requested signal list, go dump it.
        //
        dumpSignalList ( signalListFound, messagesToDump );
    }
	//
	//	Close our shared memory segment and exit.
	//
	vsi_core_close();

	//
	//	Return a good completion code to the caller.
	//
    return 0;
}