Code Monkey home page Code Monkey logo

cnatural-ncore's Introduction

NCore - Main Natural Server Program

Release 0.0.1

NCore listen in a file (a named pipe) for manage the main Natural Server.

The main named pipes (or busses) are:

  • $NATURALPATH/ipc/server/fb: FrameBuffer (the format is driver-defined).
  • $NATURALPATH/ipc/server/inputN: The input device N, the N is passed to the driver as the device fileid.
  • $NATURALPATH/ipc/server/outputN: The output device N, the N is passed to the driver as the device fileid.
  • $NATURALPATH/ipc/server/clients/connectionN: The client with the PID N.
  • $NATURALPATH/ipc/server/commander: The commander device. All commands send to this device are executed as NCore internal commands. For example: 0 drivers/output/screen/testdriver/bin/driver.so loads the test driver for handle the screen-output.

C API

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "ipcapi.h"

int main(int argc, char** argv)
{
	NCoreBool_t isServer = FALSE;
	NCoreIPCConnection_t* connection = NULL;
	char buffer[20];

	memset(buffer, '\0', 19);

	isServer = !strcmp("server", argv[1]);

	NCORE_TRY(ncore_ipc_connection_new(&connection))
	{
		fprintf(stderr, "Error creating the connection: %d\n", ncore_errno);
		exit(EXIT_FAILURE);
	}

	if(isServer)
	{
		NCORE_TRY(ncore_ipc_connection_create(connection, "./example.pipe.fifo"))
		{
			fprintf(stderr, "Error opening the rsc: %d\n", ncore_errno);

			NCORE_TRY(ncore_ipc_connection_destroy(&connection))
			{
				fprintf(stderr, "Error destroying the connection: %d\n", ncore_errno);
			}
			exit(EXIT_FAILURE);
		}

		printf("Enter anything to start to send the data\n");
		scanf("%s", buffer);

		NCORE_TRY(ncore_ipc_connection_send_fix(connection, "Hola    ", 4))
		{
			fprintf(stderr, "Error sending the data: %d\n", ncore_errno);
		}

		printf("Data sended, waiting...\n");
		scanf("%s", buffer);
	}
	else
	{
		NCORE_TRY(ncore_ipc_connection_open(connection, "./example.pipe.fifo"))
		{
			fprintf(stderr, "Error opening the rsc: %d\n", ncore_errno);

			NCORE_TRY(ncore_ipc_connection_destroy(&connection))
			{
				fprintf(stderr, "Error destroying the connection: %d\n", ncore_errno);
			}
			exit(EXIT_FAILURE);
		}

		printf("Listening...\n");
		printf("Enter anything to start to receive the data\n");
		scanf("%s", buffer);

		NCORE_TRY(ncore_ipc_connection_receive_fix(connection, buffer, 4))
		{
			fprintf(stderr, "Error receiving the data: %d\n", ncore_errno);
		}

		printf("Data receiver: %s\nEnding\n", buffer);
	}

	NCORE_TRY(ncore_ipc_connection_close(connection))
	{
		fprintf(stderr, "Error closing the connection: %d\n", ncore_errno);
		exit(EXIT_FAILURE);
	}

	NCORE_TRY(ncore_ipc_connection_destroy(&connection))
	{
		fprintf(stderr, "Error destroying the connection: %d\n", ncore_errno);
		exit(EXIT_FAILURE);
	}

	exit(EXIT_SUCCESS);
}

License

See the LICENSE file

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.