Robert Szeleney's blog

New Profiler

Submitted by Robert Szeleney on Mon, 2007-06-25 16:31.

SkyOS has got a new profiler.
The profiler itself consists of a very small kernel part which actually samples all running processes every 100 microseconds. (though the sample rate is configurable).

A server application (The ProfilerServer) collects all these sample date and builds a call graph, visualizing it in an application.
The call graph itself contains all functions down from _main to the deepest kernel function.

Features:
- Profiles the entire system, not just single applications
- User and kernel call graph
- No recompilation of application required to profile them
- Graphical call graphic visualizer

Image



Spell Checker Service

Submitted by Robert Szeleney on Mon, 2006-11-20 12:23.

A spell checker service has been implemented making it very easy to bring spell checking support to your application.

An application which wants to spell check just has to talk with the spell checking service, completely hiding the complex actual spell checking.

A short command line utility example to check a simple word and print suggestions if the word is not correct:

#include "libdcs/libdcs.h"

int main(int argc, char *argv[])

{
	sDCSInterface *pInterface;
	sDCSMessage   *pMessage;
	HRESULT hr;

	int iCorrect;
	int i;
	char str[255];

	char pWord[255];

	printf("Enter word to check: ");

	gets(pWord);

	DCS_RegisterInterface("Application.Spell.Source", &pInterface);

	DCS_AllocMessage(&pMessage, "Check");
	DCS_AddMessageString(pMessage, "Word", pWord);

	hr = DCS_SendMessage(pInterface, "Service.SpellChecker.Requests", pMessage);
	if (hr != S_OK)

	{
		printf("Spell checking service not running.\n");
		exit(1);

	}

	if (DCS_WaitForMessage(pInterface, NULL, &pMessage) == S_OK)

	{
		if (DCS_MessageGetInteger(pMessage, "Correct", &iCorrect) == S_OK)

		{
			if (iCorrect)
				printf("Word is correct.\n");

			else
			{
				printf("Word is not correct. Suggestions:\n");

				DCS_AllocMessage(&pMessage, "Suggestions");

				DCS_AddMessageString(pMessage, "Word", pWord);
				DCS_SendMessage(pInterface, "Service.SpellChecker.Requests", pMessage);

				if (DCS_WaitForMessage(pInterface, NULL, &pMessage) == S_OK)

				{
					i = 0;
					while (1)

					{
						sprintf(str, "Suggestion%d", i);
						if (DCS_MessageGetStringPtr(pMessage, str))

						{
							printf("%s\n", DCS_MessageGetStringPtr(pMessage, str));

							i++;
						}
						else
							break;
					}

				}
			}
		}
	}
}

This utility will output:

Enter word to check: heavn

Word is not correct. Suggestions:
heaven
heaving
Haven
haven
heave
heavy
Havana
having
heavens
Evan
Han
hen
Bevan
Devan
Kevan
heaver
Hahn
have
heaven's

As usual, you can easily disable/enable the service with System Manager.
This service will also be used by SkyOS GUI widgets, making it possible to auto-spell-check text in controls like edit fields and every text editor based on a text control.



A few words on desktop Communication Service

Submitted by Robert Szeleney on Tue, 2006-10-31 13:32.

Desktop Communication Service

The desktop communication service is a powerful interprocess communication system, used to communicate between applications, services, drivers and the kernel.

Internally, communication is based on messages which are based on DataCollections. Such a DataCollection Object is able to store an unlimited number of various datatypes like strings, values, etc.

Communication itself is done between interfaces, regardless where the interface exists. (kernel or user mode, application or driver, ...). This way it is very easy to, for instance,
send a message from a device driver to user applications.
Lets consider the USB stack and device attachement.
When the USB stack initialized a new just attached device it will send following message:

MessageType STRING "Attachement"
DeviceType STRING "Printer"
DevicePath STRING "/dev/usblp0"
Product STRING "Desktjet 5550C"
Manufacturer STRING "HP"
Status STRING "Ready"

to the interface Notify.Device.Attachement.*

The * in the interface name means: Send this message to all applications waiting for messages on interfaces starting with Notify.Device.Attachement.
For instance, on a fresh SkyOS installation, there are two applications waiting for messages on this interface. The notification panel - which informs you with a little message window at the bottom left side of the screen - waits for messages on Notify.Device.Attachement.Application.NotificationPanel. Additionally, the HardwareChangeService waits on Notify.Device.Attachement.Service.HardwareChange, immediately displaying the printer configuration dialog when you attached the printer.

Communication between applications is also done using the Desktop communication interface. For instance, sending this message:
MessageType STRING "Next Song"

to Notify.Media.Player.Control will cause all running mediaplayer applications to switch to the next song.

But sending the same message to

Notify.Media.Player.Control.MediaLibrary

will only tell MediaLibary to switch to the next song. Other media applications will continue playing the current song.

So, lets say you want to write an application displaying the current battery level. Thats quite easy:

#include "skyos/libskyos.h"
#include "libdcs/libdcs.h"
#include "skygi/skygi.h"

s_gi_msg m;

HRESULT Callback(HANDLE hInterface, sDCSMessage *pMessage,
char *pSource,
float fLevel)
{
printf("Battery level for '%s' is %f %%\n", pSource, fLevel);
return S_OK;
}

int main(void)
{
HANDLE hNode;

RemoteInterface_Create("Notify.Power.Battery.Change.MyApp", Callback, &hNode);
RemoteInterface_AddParameter(hNode, "Source", REMOTE_INTERFACE_PARAMETER_STRING,
"Level", REMOTE_INTERFACE_PARAMETER_FLOAT,
NULL);

RemoteInterface_Enable(hNode);

while (1)
GI_MessageWait(&m, NULL);
}

Thats all. When running this application, everytime the battery level changes you will see something like this:

Battery level for 'Primary battery' is 98%
Battery level for 'Primary battery' is 97%
Battery level for 'Primary battery' is 96%
....
....

Many similar things can be done with just this few lines of code, like :

  • reacting when the user made network interface changes or new proxy settings
  • new weather data arrived
  • new devices attached
  • devices removed
  • disks mounted/unmounted (e.g. Open viewer window or add desktop icon)
  • a song finished playing
  • new software has been installed
  • a gesture was drawn onto the screen
  • a failed login
  • an operation was not allowed because of security policy
  • etc.

Additionally you can perform actions by just sending such messages, for instance:

  • Power done, logout
  • Remote control applications (like mediaplayer, ...)
  • Soft-detach devices
  • etc.

To conclude, the Desktop Communication Service allows easy, fast, consistent and powerful communication between the kernel, drivers, services and applications.



Composing internals and an example

Submitted by Robert Szeleney on Tue, 2006-07-18 11:26.


Indexfeeder explained

Submitted by Robert Szeleney on Wed, 2006-07-12 14:36.

This blog entry will try to explain a few technical details about the Query system in combination with the new "People" files.

To begin, take a look at this screenshots:

Desktop
Here you see the common "File open" dialog. Inside this dialog the user clicks on "Query->People" which will immediately show all your contacts.

The following section will explain what happend behind the scene when the user copied this already existing BeOS people files to SkyOS:

1. User drags people files from a BFS partition to SkyOS.

2. The indexfeeder service (running in the background always) immediately detects this file operation

3. The indexfeeder asks various plugins if anyone knows about these files

4. The "BeOS People file convert" plugin claims that it can handle this file

5. The Indexfeeder now tells the plugin to extract all possible attributes from the file and optionally index its content (attributes go into SkyFS, content into the SQL database)

6. The BeOS People file Convert plugin reads all BeOS people attribute and returns a list with the new SkyOS attributes. (It actually converts on the fly between BeOS people file attributes and SkyOS people file attributes)

7. The indexfeeder attaches this new attributes to the people file.

Note: Step 2 until step 7 just take a few milliseconds and you will not notice this at all

8. User right clicks on desktop and selects Run...

9. The "File Open" dialog appears and user clicks on "People"

10. The "File Open" dialog tells the indexfeeder that it should start a new query

11. The indexfeeder fires a query to SkyFS and also starts a thread which searchs through the SQL database to search inside files

12. Once the indexfeeder found a matching file, the "File Open" dialog asks the CategoryView if it knows about this type

13. By default, the CategoryView has a handler for "application/x-person" and knows how to display such a contact inside the results view

14. The user gets his result presented as a contact view

Of course you can just search for the name of a contact and it will display the result too:

Desktop

As you can see, the Indexfeeder is not only able to completely index your files (by attributes and content), but can also be used as "on-the-fly file converter".