Exemple #1
0
status_t
Job::_CreateAndTransferPorts()
{
	// TODO: prefix system ports with "system:"

	bool defaultPort = false;

	for (PortMap::iterator iterator = fPortMap.begin();
			iterator != fPortMap.end(); iterator++) {
		BString name(Name());
		const char* suffix = iterator->second.GetString("name");
		if (suffix != NULL)
			name << ':' << suffix;
		else
			defaultPort = true;

		const int32 capacity = iterator->second.GetInt32("capacity",
			B_LOOPER_PORT_DEFAULT_CAPACITY);

		port_id port = create_port(capacity, name.String());
		if (port < 0)
			return port;

		status_t result = set_port_owner(port, fTeam);
		if (result != B_OK)
			return result;

		iterator->second.SetInt32("port", port);

		if (name == "x-vnd.haiku-registrar:auth") {
			// Allow the launch_daemon to access the registrar authentication
			BPrivate::set_registrar_authentication_port(port);
		}
	}

	if (fCreateDefaultPort && !defaultPort) {
		BMessage data;
		data.AddInt32("capacity", B_LOOPER_PORT_DEFAULT_CAPACITY);

		port_id port = create_port(B_LOOPER_PORT_DEFAULT_CAPACITY, Name());
		if (port < 0)
			return port;

		status_t result = set_port_owner(port, fTeam);
		if (result != B_OK)
			return result;

		data.SetInt32("port", port);
		AddPort(data);
	}

	return B_OK;
}
Exemple #2
0
port_id
_user_create_port(int32 queueLength, const char *userName)
{
	char name[B_OS_NAME_LENGTH];

	if (userName == NULL)
		return create_port(queueLength, NULL);

	if (!IS_USER_ADDRESS(userName)
		|| user_strlcpy(name, userName, B_OS_NAME_LENGTH) < B_OK)
		return B_BAD_ADDRESS;

	return create_port(queueLength, name);
}
DView::DView(BRect bounds)
	:
	BView(bounds, "graphics card view", B_FOLLOW_ALL, 0)
{
	SetViewColor(B_TRANSPARENT_COLOR);
#ifndef INPUTSERVER_TEST_MODE
	fInputPort = create_port(200, SERVER_INPUT_PORT);
#else
	fInputPort = create_port(100, "ViewInputDevice");
#endif

#ifdef ENABLE_INPUT_SERVER_EMULATION
	AddFilter(new DirectMessageFilter(this));
#endif
}
Exemple #4
0
/*
 * register client and create ports
 */
static int __init
register_client(void)
{
	snd_seq_client_callback_t cb;
	snd_seq_client_info_t cinfo;
	snd_seq_dummy_port_t *rec1, *rec2;
	int i;

	if (ports < 1) {
		snd_printk(KERN_ERR "invalid number of ports %d\n", ports);
		return -EINVAL;
	}

	/* create client */
	memset(&cb, 0, sizeof(cb));
	cb.allow_input = 1;
	cb.allow_output = 1;
	my_client = snd_seq_create_kernel_client(NULL, SNDRV_SEQ_CLIENT_DUMMY, &cb);
	if (my_client < 0)
		return my_client;

	/* set client name */
	memset(&cinfo, 0, sizeof(cinfo));
	cinfo.client = my_client;
	cinfo.type = KERNEL_CLIENT;
	strcpy(cinfo.name, "Midi Through");
	snd_seq_kernel_client_ctl(my_client, SNDRV_SEQ_IOCTL_SET_CLIENT_INFO, &cinfo);

	/* create ports */
	for (i = 0; i < ports; i++) {
		rec1 = create_port(i, 0);
		if (rec1 == NULL) {
			snd_seq_delete_kernel_client(my_client);
			return -ENOMEM;
		}
		if (duplex) {
			rec2 = create_port(i, 1);
			if (rec2 == NULL) {
				snd_seq_delete_kernel_client(my_client);
				return -ENOMEM;
			}
			rec1->connect = rec2->port;
			rec2->connect = rec1->port;
		}
	}

	return 0;
}
/*!	\brief Constructor

	This loads the default fonts, allocates all the major global variables,
	spawns the main housekeeping threads, loads user preferences for the UI
	and decorator, and allocates various locks.
*/
AppServer::AppServer()
	:
	MessageLooper("app_server"),
	fMessagePort(-1),
	fDesktops(),
	fDesktopLock("AppServerDesktopLock")
{
	openlog("app_server", 0, LOG_DAEMON);

	fMessagePort = create_port(DEFAULT_MONITOR_PORT_SIZE, SERVER_PORT_NAME);
	if (fMessagePort < B_OK)
		debugger("app_server could not create message port");

	fLink.SetReceiverPort(fMessagePort);

	sAppServer = this;

	gInputManager = new InputManager();

	// Create the font server and scan the proper directories.
	gFontManager = new FontManager;
	if (gFontManager->InitCheck() != B_OK)
		debugger("font manager could not be initialized!");

	gFontManager->Run();

	gScreenManager = new ScreenManager();
	gScreenManager->Run();

	// Create the bitmap allocator. Object declared in BitmapManager.cpp
	gBitmapManager = new BitmapManager();
}
void nsToolkit::RunPump(void* arg)
{
  int32		code;
  char		portname[64];
  ThreadInterfaceData id;
#ifdef DEBUG
  printf("TK-RunPump\n");
#endif
  ThreadInitInfo *info = (ThreadInitInfo*)arg;
  PR_EnterMonitor(info->monitor);

  gThreadState = PR_TRUE;

  PR_Notify(info->monitor);
  PR_ExitMonitor(info->monitor);

  delete info;

  // system wide unique names
  PR_snprintf(portname, sizeof(portname), "event%lx", 
              (long unsigned) PR_GetCurrentThread());

  port_id event = create_port(200, portname);

  while(read_port_etc(event, &code, &id, sizeof(id), B_TIMEOUT, 1000) >= 0)
  {
          MethodInfo *mInfo = (MethodInfo *)id.data;
          mInfo->Invoke();
          if(id.waitingThread != 0)
            resume_thread(id.waitingThread);
          delete mInfo;
  }
}
int
main()
{
	port_id port = create_port(1, "test port");
	printf("created port %ld\n", port);

	thread_id threads[THREAD_COUNT];
	for (int32 i = 0; i < THREAD_COUNT; i++) {
		threads[i] = spawn_thread(read_thread, "read thread", B_NORMAL_PRIORITY,
			(void*)port);
		resume_thread(threads[i]);
	}

	printf("snooze for a bit, all threads should be waiting now.\n");
	snooze(100000);

	for (int32 i = 0; i < THREAD_COUNT; i++) {
		size_t bytes = 20 + i;
		char buffer[bytes];
		memset(buffer, 0x55, bytes);

		printf("send %ld bytes\n", bytes);
		write_port(port, 0x42, buffer, bytes);
		snooze(10000);
	}

	printf("waiting for threads to terminate\n");
	for (int32 i = 0; i < THREAD_COUNT; i++) {
		wait_for_thread(threads[i], NULL);
	}

	return 0;
}
Exemple #8
0
TEST_F(UtilsTest, create_port_test)
{
	std::string id("12");
	unsigned short port = create_port(id);

	ASSERT_EQ(port, 0x3231);
}
int
main()
{
	status_t s;
	ssize_t size;
	int32 code;
	
	id = create_port(1, "test port");
	printf("created port %ld\n", id);
	
	s = write_port(id, 0x1234, data, 10);
	printf("write port result 0x%08lx (%s)\n", s, strerror(s));

	size = read_port(id, &code, data, sizeof(data)); 
	printf("read port code %lx, size %ld (0x%08lx) (%s)\n", code, size, size, strerror(size));

	printf("port_buffer_size should block for 5 seconds now, as port is empty\n");
	
	thread_id thread = spawn_thread(test_thread, "test thread", B_NORMAL_PRIORITY, NULL);
	resume_thread(thread);
	snooze(5000000);

	printf("write port...\n");
	s = write_port(id, 0x5678, data, 20);
	printf("write port result 0x%08lx (%s)\n", s, strerror(s));

	printf("waiting for thread to terminate\n");
	wait_for_thread(thread, &s);
	
	return 0;
}
Exemple #10
0
// init_connection
status_t
init_connection()
{
	status_t error = B_OK;
	// create a port
	outputPort = create_port(10, "common test app port");
	if (outputPort < 0)
		error = outputPort;
	// find the remote port
	port_id port = -1;
	if (error == B_OK) {
		port = find_port(kAppRunnerTeamPort);
		if (port < 0)
			error = port;
	}
	// send the port ID
	if (error == B_OK) {
		ssize_t written = write_port(port, outputPort, &be_app_messenger,
									 sizeof(BMessenger));
		if (written < 0)
			error = written;
	}
	connectionEstablished = (error == B_OK);
	return error;
}
Exemple #11
0
ColorField::ColorField(color_mode mode, float fixed_value)
	:
	BControl("color field", "", new BMessage(MSG_COLOR_FIELD),
		B_WILL_DRAW | B_FRAME_EVENTS),
	fColorMode(mode),
	fFixedValue(fixed_value),
	fMarkerPosition(BPoint(0.0, 0.0)),
	fLastMarkerPosition(BPoint(-1.0, -1.0)),
	fMouseDown(false),
	fUpdateThread(0),
	fUpdatePort(0)
{
	SetViewColor(B_TRANSPARENT_32_BIT);
	SetExplicitMinSize(BSize(COLOR_FIELD_WIDTH, COLOR_FIELD_HEIGHT));
	SetExplicitMaxSize(BSize(COLOR_FIELD_WIDTH, COLOR_FIELD_HEIGHT));

	for (int i = 0; i < 2; ++i) {
		fBgBitmap[i] = new BBitmap(COLOR_FIELD_RECT, B_RGB32, true, true);
		fBgBitmap[i]->Lock();

		fBgView[i] = new BView(COLOR_FIELD_RECT, "", B_FOLLOW_NONE, B_WILL_DRAW);
		fBgBitmap[i]->AddChild(fBgView[i]);
		fBgView[i]->SetOrigin(2.0, 2.0);

		fBgBitmap[i]->Unlock();
	}

	_DrawBorder();

	fUpdatePort = create_port(100, "color field update port");

	fUpdateThread = spawn_thread(&ColorField::_UpdateThread,
		"color field update thread", 10, this);
	resume_thread(fUpdateThread);
}
Exemple #12
0
extern "C" int32
tracker_loop(void *data)
{
	// create global messaging port
	
	gTrackerPort = create_port(128, "fsh tracker port");
	if (gTrackerPort < FS_OK)
		return gTrackerPort;

	while (true) {
		update_message message;
		int32 code;
		status_t status = read_port(gTrackerPort, &code, &message, sizeof(message));
		if (status < FS_OK)
			continue;

		if (code == FSH_KILL_TRACKER)
			break;

		if (code == FSH_NOTIFY_LISTENER) {
			printf("tracker: notify listener received\n");
			if (message.op != B_ATTR_CHANGED && message.op != B_DEVICE_UNMOUNTED)
				tracker_query_file(message.device, message.parentNode, message.name);
		} else if (code == B_QUERY_UPDATE) {
			printf("tracker: query update received\n");
			tracker_query_file(message.device, message.parentNode, message.name);
		} else {
			printf("tracker: unknown code received: 0x%lx\n", code);
		}
	}

	delete_port(gTrackerPort);
	return FS_OK;
}
Exemple #13
0
/*! Creates a connection with the desktop.
*/
status_t
create_desktop_connection(ServerLink* link, const char* name, int32 capacity)
{
	port_id serverPort = get_app_server_port();
	if (serverPort < 0)
		return serverPort;

	// Create the port so that the app_server knows where to send messages
	port_id clientPort = create_port(capacity, name);
	if (clientPort < 0)
		return clientPort;

	link->SetTo(serverPort, clientPort);

	link->StartMessage(AS_GET_DESKTOP);
	link->Attach<port_id>(clientPort);
	link->Attach<int32>(getuid());
	link->AttachString(getenv("TARGET_SCREEN"));
	link->Attach<int32>(AS_PROTOCOL_VERSION);

	int32 code;
	if (link->FlushWithReply(code) != B_OK || code != B_OK) {
		link->SetSenderPort(-1);
		return B_ERROR;
	}

	link->Read<port_id>(&serverPort);
	link->SetSenderPort(serverPort);

	return B_OK;
}
Exemple #14
0
/* init_channel:
 *  This function will be called when a channel is created, before any 
 *  data is sent.  It should at least set the channel's return address to
 *  something meaningful or at least to a valid string if the driver can't
 *  supply a return address.  It can allocate memory, pointed to by the
 *  `data' field of the channel struct.  Return zero if successful, non-zero
 *  otherwise.
 */
static int local_init_channel(NET_CHANNEL *chan, const char *addr)
{
    channel_data_t *data;
    port_t *port;
    int num;

    MUTEX_LOCK(port_list);

    num = parse_address(addr);
    if (num < 0) {
	MUTEX_UNLOCK(port_list);
	return -1;
    }
    
    port = create_port(num);

    /* We don't need the lock any more because `create_port' incremented
     * the usage counter on the port, so it won't vanish, and we're not 
     * dereferencing the pointer any more. */
    MUTEX_UNLOCK(port_list);

    if (!port)
        return -1;
    
    sprintf(chan->local_addr, "%d", num);

    chan->data = data = malloc(sizeof *data);
    data->port = port;
    data->target = -1;
    
    return 0;
}
Exemple #15
0
/*!	Creates a connection with the desktop.
*/
status_t
create_desktop_connection(ServerLink* link, const char* name, int32 capacity)
{
	// Create the port so that the app_server knows where to send messages
	port_id clientPort = create_port(capacity, name);
	if (clientPort < 0)
		return clientPort;

	link->SetReceiverPort(clientPort);

	BMessage request(AS_GET_DESKTOP);
	request.AddInt32("user", getuid());
	request.AddInt32("version", AS_PROTOCOL_VERSION);
	request.AddString("target", getenv("TARGET_SCREEN"));

	BMessenger server("application/x-vnd.Haiku-app_server");
	BMessage reply;
	status_t status = server.SendMessage(&request, &reply);
	if (status != B_OK)
		return status;

	port_id desktopPort = reply.GetInt32("port", B_ERROR);
	if (desktopPort < 0)
		return desktopPort;

	link->SetSenderPort(desktopPort);
	return B_OK;
}
Exemple #16
0
status_t
BTeamDebugger::Install(team_id team)
{
	Uninstall();

	// create a debugger port
	char name[B_OS_NAME_LENGTH];
	snprintf(name, sizeof(name), "debugger for team %" B_PRId32, team);
	fDebuggerPort = create_port(100, name);
	if (fDebuggerPort < 0)
		return fDebuggerPort;

	port_id nubPort = install_team_debugger(team, fDebuggerPort);
	if (nubPort < 0) {
		delete_port(fDebuggerPort);
		fDebuggerPort = -1;
		return nubPort;
	}

	status_t error = BDebugContext::Init(team, nubPort);
	if (error != B_OK) {
		remove_team_debugger(team);
		delete_port(fDebuggerPort);
		fDebuggerPort = -1;
		return error;
	}

	return B_OK;
}
//////////// == 
// Function to find a remote BLooper 
BMessenger *SLooper::FindOtherEnd(char *unique_name) { 
        BMessenger *rc = new BMessenger(); 
        int32 ignored; 

        FORMULATE_UNIQUE(unique_name);
        
        // find port by name 
        port_id port = find_port(unique); 
        if (port < 0) { 
                return NULL; 
        } 

        // create a port for the reply
        
        port_id myPort = create_port(1, "temporary port for answer"); 
       
        // send the request to the other end with the port of our end 
        write_port(port, 0xdeadbeef, &myPort, sizeof(myPort)); 
        
        // wait for an answer 
        ssize_t messageSize = port_buffer_size(myPort); 
        char *message = new char[messageSize]; 
        read_port(myPort, &ignored, message, messageSize); 

        // get the BMessenger out of it 
        BMessage msg; 
        msg.Unflatten(message); 
        msg.FindMessenger("messageTarget", rc); 
        
        return rc; 
}
Exemple #18
0
static struct snobj *handle_create_port(struct snobj *arg)
{
	const char *driver_name;
	const struct driver *driver;
	struct port *port;

	struct snobj *r;
	struct snobj *err;

	driver_name = snobj_eval_str(arg, "driver");
	if (!driver_name)
		return snobj_err(EINVAL, "Missing 'driver' field in arg");

	driver = find_driver(driver_name);
	if (!driver)
		return snobj_err(ENOENT, "No port driver '%s' found",
				driver_name);

	port = create_port(snobj_eval_str(arg, "name"), driver, 
			snobj_eval(arg, "arg"), &err);
	if (!port)
		return err;

	printf("Port %s created at %p\n", port->name, port);

	r = snobj_map();
	snobj_map_set(r, "name", snobj_str(port->name));

	return r;
}
Exemple #19
0
/** CONSTRUCTOR */
SerialPort::SerialPort(int connect) {
   _connection = (!connect);

   if(_connection) {
      _port_fd = create_port();
      configure_port();
   }
}
Exemple #20
0
// get_reply_port
static
port_id
get_reply_port()
{
	static port_id id = -1;
	if (id < 0)
		id = create_port(1, "stat cache reply port");
	return id;
}
Exemple #21
0
/*** MAIN LOOP ***/
int main(int argc, char *argv[])
{
#if	DEBUG
	bmem = AvailMem( MEMF_PUBLIC );
#endif

	ParseArgs(&args, argc, argv);

	/* Look first if Jano isn't already running */
	if( find_janoed( &args ) ) cleanup(0, RETURN_OK);

	/* Some global initialization */
	init_searchtable();

	/* Optionnal libraries */
	AslBase      = (struct Library *)    OpenLibrary("asl.library",     36);
	LocaleBase   = (struct LocaleBase *) OpenLibrary("locale.library",  38);
	DiskfontBase = (struct Library *)    OpenLibrary("diskfont.library", 0);
	IFFParseBase = (struct Library *)    OpenLibrary("iffparse.library",36);

	if(LocaleBase) InitLocale();    /* Localize the prog */

	/* Open the required ROM libraries */
	if( (IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 36)) &&
	    (GfxBase       = (struct GfxBase *)       OpenLibrary("graphics.library",  36)) &&
	    (GadToolsBase  = (struct Library *)       OpenLibrary("gadtools.library",  36)) &&
	    (KeymapBase    = (struct Library *)       OpenLibrary("keymap.library",    36)) &&
		 (UtilityBase   = (struct UtilityBase *)   OpenLibrary("utility.library",   36)) )
	{
		init_macros();
		set_default_prefs(&prefs, IntuitionBase->ActiveScreen);
		
		load_prefs(&prefs, NULL);     /* See if it exists a config file */
		sigport = create_port();

		/* Create whether an empty project or an existing one */
		if( ( edit = create_projects(NULL, args.sa_ArgLst, args.sa_NbArgs) ) )
		{
			/* Open the main interface */
			if(setup() == 0)
			{
				/* Makes edit project visible */
				reshape_panel(edit);
				active_project(edit,TRUE);
				clear_brcorner();

				dispatch_events();

			} else cleanup(ErrMsg(ERR_NOGUI), RETURN_FAIL);
		}
	} else cleanup(ErrMsg(ERR_BADOS), RETURN_FAIL);

	/* Hope that all were well... */
	cleanup(0, RETURN_OK);
	
	return 0;
}
/* Design: 
        - bind to a port, listening for a message to come in.  Put that port on a unique name so it can be found. 
        - the message ID is ignored 
        - the message payload is a port_id 
        
        - send back to that port_id a flattened BMessenger 
*/ 
SLooper::SLooper(char *unique_name, int32 prio, int32 cap) 
 : BLooper(unique_name, prio, cap) { 
        // make a port with a unique name
        FORMULATE_UNIQUE(unique_name);
        
        finder = create_port(10, unique); 
        
        // spawn a thread to answer requests to find ourselves 
        finderThread = spawn_thread(RunFinderThread, "message loop finder thread", B_DISPLAY_PRIORITY, this); 
        resume_thread(finderThread); 
} 
Exemple #23
0
void Chat::join(const std::string& peer_id, const std::string& peer_ip)
{
	std::string peer_ep;
	unsigned short peer_port = create_port(peer_id);
	peer_ep = (boost::format("tcp://%s:%d") % peer_ip % peer_port).str();

	if(zmq_connect(subscriber_, peer_ep.c_str()) < 0)
	{
		zmq_strerror(errno);
	}
}
Exemple #24
0
void HighScores::Go(void)
{
long foo;

	Port = create_port(1, "BShisen Port #2");
	Show();

	// block until the some action occurs
	read_port(Port, &foo, NULL, 0);

}
Exemple #25
0
BAppServerLink::BAppServerLink(void)
 : BPortLink()
{
	if (be_app)
	{
		be_app->Lock();
		SetSendPort(be_app->fServerFrom);
	}
	receiver=create_port(100,"AppServerLink reply port");
	SetReplyPort(receiver);

}
Exemple #26
0
void Chat::leave(const std::string& peer_id, const std::string& peer_ip)
{
	std::string peer_ep;
	unsigned short peer_port = create_port(peer_id);
//	peer_ep = std::string("tcp://*:") + boost::lexical_cast<std::string>(peer_port);
	peer_ep = (boost::format("tcp://%s:%d") % peer_ip % peer_port).str();

	if (zmq_disconnect(subscriber_, peer_ep.c_str()) < 0)
	{
		zmq_strerror(errno);
	}
}
static port_id
get_command_port()
{
	static port_id port = -1;
	static bool initialized = false;

	if (!initialized) {
		port = create_port(10, kFSShellCommandPort);
		initialized = true;
	}

	return port;
}
Exemple #28
0
MediaAddonServer::MediaAddonServer(const char* signature)
	:
	BApplication(signature),
	fStartup(true),
	fStartupSound(true)
{
	CALLED();
	fMediaRoster = BMediaRoster::Roster();
	fControlPort = create_port(64, MEDIA_ADDON_SERVER_PORT_NAME);
	fControlThread = spawn_thread(_ControlThread, "media_addon_server control",
		B_NORMAL_PRIORITY + 2, this);
	resume_thread(fControlThread);
}
void
SyslogDaemon::ReadyToRun()
{
	fPort = create_port(256, SYSLOG_PORT_NAME);
	fDaemon = spawn_thread(daemon_thread, "daemon", B_NORMAL_PRIORITY, this);

	if (fPort >= B_OK && fDaemon >= B_OK) {
		init_syslog_output(this);
		init_listener_output(this);

		resume_thread(fDaemon);
	} else
		Quit();
}
Exemple #30
0
int main()
{
    Q = InitQ(Q);                            //Modification to initialize the run queue
    int i;
    for(i = 0; i < 100; i++)
        create_port(10, i);                  // Initializes all the ports
    start_thread(serverport0);               // Only argument passed to thead_start is function name
    start_thread(serverport1); 
    start_thread(client);
    start_thread(client);
    start_thread(client);
    start_thread(client);
    run();                                  //Since run function is non-terminating we do not require an infinite loop in main
}