Skip to content
Snippets Groups Projects
Select Git revision
  • 34af9327d85d21e15fc4d452d0882f6265337fa4
  • main default protected
  • Issue/3141-rdsNoLonga
  • Issue/3180-fixMetadataNotLoading
  • dev protected
  • Issue/3177-resourceTypeDescriptionTexts
  • Issue/3090-tosProblems
  • Issue/3178-iconColorBug
  • Issue/3160-deactivateDownloadForFolders
  • Issue/3111-fixLoadingGitLabResource
  • Issue/3133-subProjectsChanges
  • Issue/3139-dsnrw
  • Issue/3167-changeTextAndAddLink
  • Issue/3070-newIconsForResourceTypes
  • Issue/3145-redesignLoginPage
  • Issue/3093-moreInformationInTheDeletionEmails
  • Issue/3040-closeTokenWindowWithXButton
  • Issue/3152-fixResourceStore
  • Issue/xxxx-DuckDBTest
  • Issue/3152-fixUpdateRequestPayload
  • Issue/2489-addNotificationManagement
  • v3.19.1
  • v3.19.0
  • v3.18.0
  • v3.17.2
  • v3.17.1
  • v3.17.0
  • v3.16.1
  • v3.16.0
  • v3.15.6
  • v3.15.5
  • v3.15.4
  • v3.15.3
  • v3.15.2
  • v3.15.1
  • v3.15.0
  • v3.14.0
  • v3.13.1
  • v3.13.0
  • v3.12.0
  • v3.11.0
41 results

FilesViewHeader.vue

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    vasingletonmethods.hpp 3.69 KiB
    #include <Python.h>
    #include <VANetClient.h>
    #include <VACore.h>
    #include <VAException.h>
    #include <string.h>
    
    // If you want to extend the va Python pSelf interface, also add
    // the function to the va_methods table in vasingleton.cpp - otherwise they will not show up.
    // Documentation goes into vasingletondoc.hpp
    
    static IVANetClient* g_pVANetClient = nullptr; //!< Static pointer to VANetClient instance
    static PyObject* g_pVAError = nullptr; //!< Static pointer to error instance
    
    //! Helper for API dev
    static PyObject* va_not_implemented( PyObject* pSelf, PyObject** ppArgs, Py_ssize_t nArgs, PyObject* pKeywordNames )
    {
    	VA_EXCEPT_NOT_IMPLEMENTED;
    	return NULL;
    }
    
    //! Raises an exception if core is not available
    static void RequireCoreAvailable()
    {
    	if( !g_pVANetClient )
    		VA_EXCEPT2( CVAException::NETWORK_ERROR, "VA client not available, please connect first" );
    
    	if( !g_pVANetClient->GetCoreInstance() )
    		VA_EXCEPT2( CVAException::NETWORK_ERROR, "VA client available, but access to VA interface failed. Please reconnect." );
    }
    
    static PyObject* va_connect( PyObject* pSelf, PyObject** ppArgs, Py_ssize_t nArgs, PyObject* pKeywordNames )
    {
    	if( !g_pVANetClient )
    		g_pVANetClient = IVANetClient::Create();
    
    	if( g_pVANetClient->IsConnected() )
    	{
    		PyErr_Warn( pSelf, "Was still connected, forced disconnect." );
    		g_pVANetClient->Disconnect();
    	}
    
    	static const char * const _keywords[] = { "server", "port", NULL };
    	static _PyArg_Parser _parser = { "Oi:connect", _keywords, 0 };
    	PyObject* pServer;
    	PyObject* pPort;
    
    	if( !_PyArg_ParseStack( ppArgs, nArgs, pKeywordNames, &_parser, &pServer, &pPort ) )
    		return PyBool_FromLong( 0 );
    
    	std::string sServerIP = "localhost";
    	char* pcServerIP = nullptr;
    	if( PyArg_ParseTuple( pPort, "i", &pcServerIP ) )
    		sServerIP = std::string( pcServerIP );
    
    	int iServerPort = 12340;
    	int* piServerPort = nullptr;
    	if( PyArg_ParseTuple( pPort, "i", &piServerPort ) )
    		iServerPort = *piServerPort;
    
    	if( IVANetClient::VA_NO_ERROR == g_pVANetClient->Initialize( sServerIP, iServerPort ) )
    		return PyBool_FromLong( 1 );
    
    	PyErr_SetString( PyExc_ConnectionError, std::string( "Could not connect to " + sServerIP + " on " + std::to_string( ( long ) iServerPort ) ).c_str() );
    
    	return NULL;
    }
    
    static PyObject* va_disconnect( PyObject* pSelf, PyObject** ppArgs, Py_ssize_t nArgs, PyObject* pKeywordNames )
    {
    	if( g_pVANetClient )
    		g_pVANetClient->Disconnect();
    
    	return PyBool_FromLong( 1 );
    }
    static PyObject* va_is_connected( PyObject* pSelf, PyObject** ppArgs, Py_ssize_t nArgs, PyObject* pKeywordNames )
    {
    	if( !g_pVANetClient )
    		return PyBool_FromLong( 0 );
    	else
    		return PyBool_FromLong( g_pVANetClient->IsConnected() );
    }
    
    static PyObject* va_reset( PyObject* pSelf, PyObject** ppArgs, Py_ssize_t nArgs, PyObject* pKeywordNames )
    {
    	RequireCoreAvailable();
    
    	g_pVANetClient->GetCoreInstance()->Reset();
    
    	return PyBool_FromLong( 1 );
    }
    
    static PyObject* va_enumerate_modules( PyObject* pSelf, PyObject** ppArgs, Py_ssize_t nArgs, PyObject* pKeywordNames )
    {
    	RequireCoreAvailable();
    
    	VA_EXCEPT_NOT_IMPLEMENTED;
    
    	return NULL;
    }
    
    static PyObject* va_call_module( PyObject* pSelf, PyObject** ppArgs, Py_ssize_t nArgs, PyObject* pKeywordNames )
    {
    	RequireCoreAvailable();
    
    	VA_EXCEPT_NOT_IMPLEMENTED;
    
    	return NULL;
    }
    
    static PyObject* va_add_search_path( PyObject* pSelf, PyObject** ppArgs, Py_ssize_t nArgs, PyObject* pKeywordNames )
    {
    	RequireCoreAvailable();
    
    	VA_EXCEPT_NOT_IMPLEMENTED;
    
    	return NULL;
    }
    
    static PyObject* va_create_listener( PyObject* pSelf, PyObject** ppArgs, Py_ssize_t nArgs, PyObject* pKeywordNames )
    {
    	RequireCoreAvailable();
    
    	std::string sName = "PyListener";
    	int iID = g_pVANetClient->GetCoreInstance()->CreateListener( sName, IVACore::VA_AURAMODE_ALL );
    
    	return PyLong_FromLong( iID );
    }