Example #1
0
void
RegisterWindow(void)
{
	sWindowLocker.Lock();
	sWindowCount++;
	sWindowLocker.Unlock();
}
static void
listener_output(syslog_message &message)
{
	// compose the message to be sent to all listeners; just convert
	// the syslog_message into a BMessage
	BMessage output(SYSLOG_MESSAGE);

	output.AddInt32("from", message.from);
	output.AddInt32("when", message.when);
	output.AddString("ident", message.ident);
	output.AddString("message", message.message);
	output.AddInt32("options", message.options);
	output.AddInt32("priority", message.priority);

	sLocker.Lock();

	for (int32 i = sListeners.CountItems(); i-- > 0;) {
		BMessenger *target = (BMessenger *)sListeners.ItemAt(i);

		status_t status = target->SendMessage(&output);
		if (status < B_OK) {
			// remove targets once they can't be reached anymore
			sListeners.RemoveItem(target);
		}
	}

	sLocker.Unlock();
}
Example #3
0
    int
    getextmntent_haiku(int* cookie, struct extmnttab *mp, int len)
    {
        static BLocker extmntent_locker;
        extmntent_locker.Lock();

        BVolumeRoster roster;
        BVolume volume;
        int ret = -1;

        roster.Rewind();
        for (int i = 0; i <= *cookie; i++)
            if (roster.GetNextVolume(&volume) != B_NO_ERROR)
                return -1;

        if (getmntent_haiku(cookie, (struct mnttab*)mp) == 0) {
            mp->mnt_major = volume.Device();
            mp->mnt_minor = volume.Device();

            ret = 0;
        }

        extmntent_locker.Unlock();
        return ret;
    }
Example #4
0
status_t WatchNode (node_ref node, uint32 flags, const BHandler *handler, const BLooper *looper)
{
	/* Allocate a node monitor normally */	
	codeLocker.Lock();
	status_t result = watch_node (&node, flags, handler, looper);
	if (result == B_OK || result != B_NO_MEMORY)
	{
		codeLocker.Unlock();
		return result;
	}
	
	/* Failed to start monitor, try to allocate more monitors */
	result = NeedMoreNodeMonitors();

	/* Failed to allocate more monitors */
	if (result != B_OK)
	{
		codeLocker.Unlock();
		return result;
	}
	
	/* Try again, this time with more node monitors */
	codeLocker.Unlock();
	return watch_node (&node, flags, handler, looper);
}
Example #5
0
status_t WatchNode (BEntry *entry, uint32 flags, const BHandler *handler, const BLooper *looper)
{
	codeLocker.Lock();

	/* Derive a node_ref from the entry received */
	node_ref node;
	entry->GetNodeRef (&node);


	/* Allocate a node monitor normally */	
	status_t result = watch_node (&node, flags, handler, looper);
	if (result == B_OK || result != B_NO_MEMORY)
	{
		codeLocker.Unlock();
		return result;
	}
	
	
	/* Failed to start monitor, try to allocate more monitors */
	result = NeedMoreNodeMonitors();


	/* Failed to allocate more monitors */
	if (result != B_OK)
	{
		codeLocker.Unlock();
		return result;
	}
	
	
	codeLocker.Unlock();
	
	/* Try again, this time with more node monitors */
	return watch_node (&node, flags, handler, looper);
}
Example #6
0
Status* FindStatus(BString abbreviation)
{
	statLock.Lock();
	Status *status = statusses[abbreviation];
	statLock.Unlock();
	
	return status;
}
Example #7
0
void GlobalMutex::Unlock()
{
//	assert( g_cLock.LockingThread() == getpid() );
//	assert( g_cLock.LockingThread() == GetCurLooper()->Thread() );
//	assert( g_cLock.LockingThread() == find_thread(NULL) );
	assert( g_cLock.IsLocked() );
	g_cLock.Unlock();
}
void 
add_listener(BMessenger *messenger)
{
	if (sLocker.Lock()) {
		sListeners.AddItem(messenger);

		sLocker.Unlock();
	}
}
void 
remove_listener(BMessenger *messenger)
{
	if (sLocker.Lock()) {
		sListeners.RemoveItem(messenger);

		sLocker.Unlock();
	}
}
Example #10
0
int32
CountRegisteredWindows(void)
{
	int32 count;
	sWindowLocker.Lock();
	count = sWindowCount;
	sWindowLocker.Unlock();
	return count;
}
Example #11
0
status_t NeedMoreNodeMonitors ()
{
	/* Bump node monitor count up BY "bumpValue" */
	codeLocker.Lock();
	nodeCount += bumpValue;
	codeLocker.Unlock();

	return _kset_mon_limit_ (nodeCount);
}
Example #12
0
void DeleteStatusses()
{
	statLock.Lock();
	for (SI p = statusses.begin(); p != statusses.end(); ++p)
	{
		delete (*p).second;
	}
	statLock.Unlock();
}
Example #13
0
void
PObjectBroker::UnregisterObject(PObject *obj)
{
	if (obj && !fQuitting)
	{
		sIDLock.Lock();
		fObjectList->RemoveItem(obj,false);
		sIDLock.Unlock();
	}
}
Example #14
0
void
PObjectBroker::RegisterObject(PObject *obj)
{
	if (obj)
	{
		sIDLock.Lock();
		obj->fObjectID = sNextID++;
		sIDLock.Unlock();
	}
}
Example #15
0
status_t 
BMediaFormats::RewindFormats()
{
	if (!sLock.IsLocked() || sLock.LockingThread() != find_thread(NULL)) {
		// TODO: Shouldn't we simply drop into the debugger in this case?
		return B_NOT_ALLOWED;
	}

	fIteratorIndex = 0;
	return B_OK;
}
Example #16
0
void
BufferProc(void *cookie, void *buff, size_t len, const media_raw_audio_format &format)
{
	if(settings.sound.s9x_mute) {
		memset(buff, 0, len); 
		return;
	}
	sound_locker.Lock();
	S9xMixSamples((uint8 *)buff,(so.sixteen_bit?so.buffer_size>>1:so.buffer_size));
	sound_locker.Unlock();
}
Example #17
0
Decoder *
mp3DecoderPlugin::NewDecoder(uint index)
{
	static BLocker locker;
	static bool initdone = false;
	locker.Lock();
	if (!initdone) {
		InitMpgLib();
		initdone = true;
	}
	locker.Unlock();
	return new mp3Decoder;
}
Example #18
0
/** We share one global list for all BMediaFormats in the team - since the
 *	format data can change at any time, we have to update the list to ensure
 *	that we are working on the latest data set. The list is always sorted by
 *	description. The formats lock has to be held when you call this function.
 */
static status_t
update_media_formats()
{
	if (!sLock.IsLocked())
		return B_NOT_ALLOWED;

	// We want the add-ons to register themselves with the format manager, so
	// the list is up to date.
	AddOnManager::GetInstance()->RegisterAddOns();

	BMessage reply;
	FormatManager::GetInstance()->GetFormats(sLastFormatsUpdate, reply);

	// do we need an update at all?
	bool needUpdate;
	if (reply.FindBool("need_update", &needUpdate) < B_OK)
		return B_ERROR;
	if (!needUpdate)
		return B_OK;

	// update timestamp and check if the message is okay
	type_code code;
	int32 count;
	if (reply.FindInt64("timestamp", &sLastFormatsUpdate) < B_OK
		|| reply.GetInfo("formats", &code, &count) < B_OK)
		return B_ERROR;

	// overwrite already existing formats

	int32 index = 0;
	for (; index < sFormats.CountItems() && index < count; index++) {
		meta_format* item = sFormats.ItemAt(index);

		const meta_format* newItem;
		ssize_t size;
		if (reply.FindData("formats", MEDIA_META_FORMAT_TYPE, index,
				(const void**)&newItem, &size) == B_OK)
			*item = *newItem;
	}

	// allocate additional formats

	for (; index < count; index++) {
		const meta_format* newItem;
		ssize_t size;
		if (reply.FindData("formats", MEDIA_META_FORMAT_TYPE, index,
				(const void**)&newItem, &size) == B_OK)
			sFormats.AddItem(new meta_format(*newItem));
	}

	// remove no longer used formats

	while (count < sFormats.CountItems())
		delete sFormats.RemoveItemAt(count);

	return B_OK;
}
Example #19
0
void
DeregisterWindow(void)
{
	bool quit = false;
	sWindowLocker.Lock();
	sWindowCount--;
	
	if (sWindowCount == 0)
		quit = true;
	
	sWindowLocker.Unlock();
	if (quit)
	{
		if (gQuitOnZeroWindows)
			be_app->PostMessage(B_QUIT_REQUESTED);
		else
			gQuitOnZeroWindows = 1;
	}
}
void
WPASupplicantApp::_NotifyInterfaceStateChanged(BMessage *message)
{
	const wpa_supplicant *interface;
	if (message->FindPointer("interface", (void **)&interface) != B_OK)
		return;

	if (!fWatchingEntryListLocker.Lock())
		return;

	for (int32 i = 0; i < fWatchingEntryList.CountItems(); i++) {
		StateChangeWatchingEntry *entry = fWatchingEntryList.ItemAt(i);
		if (entry->MessageReceived(interface, message)) {
			delete fWatchingEntryList.RemoveItemAt(i);
			i--;
		}
	}

	fWatchingEntryListLocker.Unlock();
}
Example #21
0
status_t 
BMediaFormats::GetNextFormat(media_format* _format,
	media_format_description* _description)
{
	if (!sLock.IsLocked() || sLock.LockingThread() != find_thread(NULL)) {
		// TODO: Shouldn't we simply drop into the debugger in this case?
		return B_NOT_ALLOWED;
	}

	if (fIteratorIndex == 0) {
		// This is the first call, so let's make sure we have current data to
		// operate on.
		status_t status = update_media_formats();
		if (status < B_OK)
			return status;
	}

	meta_format* format = sFormats.ItemAt(fIteratorIndex++);
	if (format == NULL)
		return B_BAD_INDEX;

	return B_OK;
}
status_t
WPASupplicantApp::_StartWatchingInterfaceChanges(
	const wpa_supplicant *interface, StateChangeCallback callback, void *data)
{
	StateChangeWatchingEntry *entry
		= new(std::nothrow) StateChangeWatchingEntry(interface, callback, data);
	if (entry == NULL)
		return B_NO_MEMORY;

	if (!fWatchingEntryListLocker.Lock()) {
		delete entry;
		return B_ERROR;
	}

	status_t result = B_OK;
	if (!fWatchingEntryList.AddItem(entry)) {
		result = B_ERROR;
		delete entry;
	}

	fWatchingEntryListLocker.Unlock();
	return result;
}
Example #23
0
void ArpUnlockDebugOut()
{
	gDebugLock.Unlock();
}
Example #24
0
void ArpLockDebugOut()
{
	gDebugLock.Lock();
}
Example #25
0
status_t LoadStatusses(BPath statFilePath)
{
	status_t error = B_OK;
	//open file
	BFile statFile(statFilePath.Path(), B_READ_ONLY);
	error = statFile.InitCheck();
	if (error != B_ERROR)
	{
		StringList *tokenList = new StringList();
		//read line
		off_t fileSize;
		if (statFile.GetSize(&fileSize) == B_OK)
		{			
			ssize_t bytesRead = 0;
			BString* token = new BString("");
			bool newToken = false;			
			do
			{
				char c[2];				
				bytesRead += statFile.Read(c,1);
				c[1] = '\0';				
				
				if (c[0] == '\t' || c[0] == '\n')
				{
					//clear token
					if (!newToken)
					{
						//add token to list
						tokenList->AddItem(token);						
						token = new BString("");				
						newToken = true;
					}
				}
				else 
				{
					token->Append(c);
					newToken = false;
				}
			}
			while (bytesRead < fileSize);
		}
		
		int32 startIndex = -1;
		int32 endIndex = -1;
		for (int32 i = 0; i < tokenList->CountItems(); i++)
		{
			if ((*tokenList)[i].ICompare("<status>") == 0)
				startIndex = i;
			else if ((*tokenList)[i].ICompare("</status>") == 0)
			{
				endIndex = i;
				break;
			}
		}
		
		if (startIndex != -1 && endIndex != -1)
		{
			//start past the <status> tag
			startIndex++;
			for (int32 i = startIndex; i < endIndex; i++)
			{
				int32 lastLineIndex = i + 4;

				if (lastLineIndex < endIndex)
				{
					//parse lines
					BString bitmapString = (*tokenList)[i];
					BString statusName = (*tokenList)[i+1];
					BString abbreviation = (*tokenList)[i+2];
					bool userChoice = atoi((*tokenList)[i+3].String());				
					BString colourString = (*tokenList)[i+4];
					i += 4;
					//construct bitmap path
					BPath bitmapPath;
					statFilePath.GetParent(&bitmapPath);
					bitmapPath.Append(bitmapString.String());
					BBitmap *icon = BTranslationUtils::GetBitmap(bitmapPath.Path());
					//construct status object
					Status *status = FindStatus(abbreviation);
					if (status != NULL)
					{
						status->AddIcon(icon);
					}
					else
					{
						//remove brackets from colourString
						colourString.RemoveAll("{");						
						colourString.RemoveAll("}");
						
						int32 colours[4];
						int32 startIndex = 0;						
						for (int i = 0; i < 4; i++)
						{
							int32 commaIndex = colourString.FindFirst(",",startIndex);							
							if (commaIndex != B_ERROR)
							{
								BString colourValue;
								colourString.CopyInto(colourValue,startIndex, commaIndex-startIndex);
								colours[i] = atoi(colourValue.String());
								startIndex = commaIndex + 1;
							}
							else if (i < 3)
							{								
								BString colourValue;								
								colourString.CopyInto(colourValue, startIndex, colourString.CountChars() - startIndex);
								colours[i] = atoi(colourValue.String());								
							}		
							else if (i == 3)
							{
								colours[i] = 255;
							}						
						}
						//construct status colour
						rgb_color statusColour;
						statusColour.red = colours[0];
						statusColour.green = colours[1];
						statusColour.blue = colours[2];
						statusColour.alpha = colours[3];
						//construct new status object
						Status *status = new Status(statusName,abbreviation, icon, userChoice, statusColour);
						statLock.Lock();
						statusses[abbreviation] = status;
						statLock.Unlock();	
							
					}		
				}
			}
		}
				
		StringList::deleteStrings(tokenList);
		delete tokenList;
	}	
	else
	{
		error = B_ERROR;
	}	
	return error;
}
Example #26
0
status_t 
BMediaFormats::InitCheck()
{
	return sLock.Sem() >= B_OK ? B_OK : sLock.Sem();
}
Example #27
0
bool
BMediaFormats::Lock()
{
	return sLock.Lock();
}
Example #28
0
void 
BMediaFormats::Unlock()
{
	sLock.Unlock();
}
Example #29
0
    int
    getmntent_haiku(int* cookie, struct mnttab* mp)
    {
        static BLocker mntent_locker;
        mntent_locker.Lock();

        int ret = -1;
        BVolumeRoster roster;
        char buf[B_PATH_NAME_LENGTH];
        int buflen = 0;
        BVolume volume;
        BDirectory rootDir;
        BEntry rootDirEntry;
        BPath rootDirPath;

        roster.Rewind();
        for (int i = 0; i <= *cookie; i++)
            if (roster.GetNextVolume(&volume) != B_NO_ERROR)
                goto bail;

        // volume name
        volume.GetName(buf);
        buflen = strlen(buf);

        if (buflen == 0) {
            buflen = strlen(MNTENT_MP_UNKNOWN);
            strlcpy(buf, MNTENT_MP_UNKNOWN, buflen + 1);
        }

        mp->mnt_special = (char* )malloc(sizeof(char) * (buflen+1));
        strlcpy(mp->mnt_special, buf, buflen+1);

        // mount point
        if (volume.GetRootDirectory(&rootDir) != B_OK ||
                rootDir.GetEntry(&rootDirEntry) != B_OK   ||
                rootDirEntry.GetPath(&rootDirPath) != B_OK)
            goto bail;

        buflen = strlen(rootDirPath.Path());
        mp->mnt_mountp = (char* )malloc(sizeof(char) * (buflen+1));
        strlcpy(mp->mnt_mountp, rootDirPath.Path(), buflen + 1);

        // partition type.
        fs_info info;
        if (fs_stat_dev(volume.Device(), &info) != B_OK)
            goto bail;

        buflen = strlen(info.fsh_name);
        mp->mnt_fstype = (char* )malloc(sizeof(char) * (buflen+1));
        strlcpy(mp->mnt_fstype, info.fsh_name, buflen+1);

        // fs options. set default options for all file systems for now.
        buflen = strlen(MNTENT_MP_DEFAULT_OPTS);
        mp->mnt_mntopts = (char* )malloc(sizeof(char) * (buflen+2+1)); // extra space for ro/rw
        strlcpy(mp->mnt_mntopts, MNTENT_MP_DEFAULT_OPTS, buflen + 2 + 1);
        strcat(mp->mnt_mntopts, volume.IsReadOnly() ? ",ro":",rw");

        // mount time. no idea how i can get this. set it to 0 for now.
        buflen = 1;
        mp->mnt_time = (char* )malloc(sizeof(char) * (buflen+1));
        strlcpy(mp->mnt_time, "0", buflen + 1);

        (*cookie)++;
        ret = 0; /* success! */

bail:
        mntent_locker.Unlock();
        return ret;
    }
Example #30
0
void GlobalMutex::Lock()
{
	g_cLock.Lock();
}