Exemplo n.º 1
0
    virtual void handleReceivedDataStruct(ReceivedDataStructure<RequestType>& request)
    {
        UAVCAN_ASSERT(request.getTransferType() == TransferTypeServiceRequest);

        ServiceResponseDataStructure<ResponseType> response;

        if (coerceOrFallback<bool>(callback_, true))
        {
            UAVCAN_ASSERT(response.isResponseEnabled());  // Enabled by default
            callback_(request, response);
        }
        else
        {
            handleFatalError("Srv serv clbk");
        }

        if (response.isResponseEnabled())
        {
            publisher_.setPriority(request.getPriority());      // Responding at the same priority.

            const int res = publisher_.publish(response, TransferTypeServiceResponse, request.getSrcNodeID(),
                                               request.getTransferID());
            if (res < 0)
            {
                UAVCAN_TRACE("ServiceServer", "Response publication failure: %i", res);
                publisher_.getNode().getDispatcher().getTransferPerfCounter().addError();
                response_failure_count_++;
            }
        }
        else
        {
            UAVCAN_TRACE("ServiceServer", "Response was suppressed by the application");
        }
    }
Exemplo n.º 2
0
 Entry&       getEntry(NodeID node_id)
 {
     if (node_id.get() < 1 || node_id.get() > NodeID::Max)
     {
         handleFatalError("NodeInfoRetriever NodeID");
     }
     return entries_[node_id.get() - 1];
 }
Exemplo n.º 3
0
 Entry& getEntry(NodeID node_id) const
 {
     if (node_id.get() < 1 || node_id.get() > NodeID::Max)
     {
         handleFatalError("NodeStatusMonitor NodeID");
     }
     return entries_[node_id.get() - 1];
 }
Exemplo n.º 4
0
void signal_handler(int sig) {
	printf("Signal handler: %i\n", sig);
	print_backtrace(true, true);
	if(forkExecProc)
		printf("This is a forkExec subprocess. I just quit.\n");
	else if(origPid != getpid())
		printf("This is a forked process. I just quit.\n");
	else
		handleFatalError("There was a fatal error.");
	_exit(100 + sig);
}
Exemplo n.º 5
0
 virtual void handleReceivedDataStruct(ReceivedDataStructure<DataType_>& msg)
 {
     if (try_implicit_cast<bool>(callback_, true))
     {
         callback_(msg);
     }
     else
     {
         handleFatalError("Sub clbk");
     }
 }
Exemplo n.º 6
0
CanIOManager::CanIOManager(ICanDriver& driver, IPoolAllocator& allocator, ISystemClock& sysclock,
                           std::size_t mem_blocks_per_iface)
    : driver_(driver)
    , sysclock_(sysclock)
    , num_ifaces_(driver.getNumIfaces())
{
    if (num_ifaces_ < 1 || num_ifaces_ > MaxCanIfaces)
    {
        handleFatalError("Num ifaces");
    }

    if (mem_blocks_per_iface == 0)
    {
        mem_blocks_per_iface = allocator.getNumBlocks() / (num_ifaces_ + 1U) + 1U;
    }
    UAVCAN_TRACE("CanIOManager", "Memory blocks per iface: %u, total: %u",
                 unsigned(mem_blocks_per_iface), unsigned(allocator.getNumBlocks()));

    for (int i = 0; i < num_ifaces_; i++)
    {
        tx_queues_[i].construct<IPoolAllocator&, ISystemClock&, std::size_t>
        (allocator, sysclock, mem_blocks_per_iface);
    }
}
Exemplo n.º 7
0
int main(int argc, char *argv[])
{
	sys_argc = argc;
	sys_argv = argv;
	origPid = getpid();
	
#ifdef __APPLE__
	extern void install_breakpoint_handlers();
	install_breakpoint_handlers();
#endif
	
	forkExecProc = haveArg("--forkExecProc");
	bool shell = haveArg("--shell");
	bool pyShell = haveArg("--pyshell");
	bool pyExec = haveArg("--pyexec");
	bool noLog = haveArg("--nolog");
	bool help = haveArg("--help") || haveArg("-h");
	bool beingDebugged = AmIBeingDebugged();
	
	const char* logDisabledReason = NULL;
	if(pyShell || pyExec || shell || forkExecProc || help) {} // be quiet
	else if(beingDebugged) {
		logDisabledReason = "debugger detected, not redirecting stdout/stderr";
	}
	else if(noLog) {
		logDisabledReason = "not redirecting stdout/stderr";
	}
	else {
		// current workaround to log stdout/stderr. see http://stackoverflow.com/questions/13104588/how-to-get-stdout-into-console-app
		logEnabled = true;
		printf("MusicPlayer: stdout/stderr goes to %s now\n", logFilename.c_str());
		fflush(stdout);
		int newFd = open(getTildeExpandedPath(logFilename).c_str(), O_WRONLY|O_APPEND|O_CREAT);
		dup2(newFd, fileno(stdout));
		dup2(newFd, fileno(stderr));
		close(newFd);
		//freopen(logFilename.c_str(), "a", stdout);
		//freopen(logFilename.c_str(), "a", stderr);
		stderr = stdout; // well, hack, ... I don't like two seperate buffers. just messes up the output
	}

	if(!forkExecProc) {
		printf("%s", StartupStr);
		install_signal_handler();
	}
	
	if(help) {
		printf(
			   "Help: Available options:\n"
			   "  --nolog		: don't redirect stdout/stderr to log. also implied when run in debugger\n"
			   );
	}

	if(!logEnabled && logDisabledReason)
		printf("%s\n", logDisabledReason);

	std::string mainPyFilename = getResourcePath() + "/Python/main.py";
	Py_SetProgramName(argv[0]);
	if(!forkExecProc)
		printf("Python version: %s, prefix: %s, main: %s\n", Py_GetVersion(), Py_GetPrefix(), mainPyFilename.c_str());
	
	Py_Initialize();
	PyEval_InitThreads();
	addPyPath();

	if(logEnabled) {
		PySys_SetObject((char*)"stdout", PyFile_FromFile(stdout, (char*)"<stdout>", (char*)"w", fclose));
		PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"stdout"));
	}
	PySys_SetObject((char*)"MusicPlayerBin", PyString_FromString(argv[0]));

	// Preload imp and thread. I hope to fix this bug: https://github.com/albertz/music-player/issues/8 , there was a crash in initthread which itself has called initimp
	PyObject* m = NULL;
	m = PyImport_ImportModule("imp");
	Py_XDECREF(m);
	m = PyImport_ImportModule("thread");
	Py_XDECREF(m);
	
	PySys_SetArgvEx(argc, argv, 0);
			
	FILE* fp = fopen((char*)mainPyFilename.c_str(), "r");
	if(fp)
		PyRun_SimpleFile(fp, "main.py");
	else
		printf("Could not open main.py!\n");
	
	if(!forkExecProc && !help && !pyShell && !pyExec && !shell) {
		bool successStartup = checkStartupSuccess();
		if(!successStartup) {
			printf("Error at startup.\n");
			handleFatalError("There was an error at startup.");
		}
	}
	
	return 0;
}
/**
 * Reports a fatal error that cannot be handled in Java. 
 *
 * handleFatalError(Ljava/lang/Throwable;)V
 */
KNIEXPORT KNI_RETURNTYPE_VOID
Java_com_sun_midp_events_EventQueue_handleFatalError(void) {
    handleFatalError();
}