Photon Handler and Threading

Hello :slight_smile:

i have some problems to develop my program and it would be nice to get some hints ;)

okay first i have a client who streams raw pixel data through the ethernet.

now i have a server who accepts the connection and reads the data from the socket.
Now i want a photon window that gets the raw pixel data and show the picture.
this i have solved, by save the raw pixel data to a bitmap and load the bitmap to photon.
But how can i update the photon window without to exit the program.
i want to make some kind of a “video” in my photon window.
Is there any function/handler how i can update the photon window content immediatly or need i to create a thread for the server, beacause when i start a photon window, i locks the hole program.

i hope for helpful hints :slight_smile:

with best regards


Quite honestly, I can’t figure out what you are saying your problem is.

Here is a suggestion anyway. You seem to want to transfer pixel data from a server to a photon program.
There are a number of ways you might do this. You could set things up so that your server sends a message to the photon program with the pixel data as the content. Another way would be to have some shared memory that both the server and photon program use. Load the pixel data into the shared memory and then have the server either send a message or a pulse to the photon program.

Once the photon program gets the pixel data, it can put it into an image structure (if it isn’t already in one) and then either update a widget or do a direct graphical draw to raw widget.

I have no idea why you think you need to exit the photon program to reshow the data. I also can’t tell what you mean about locking up a program when you start a window.

Hey :slight_smile:

sry for my bad introducing of my problem.

Okay i have two threads: tcpServer who accepts the incoming Clientconnections and read the raw pixel data from the socket and a Photon application which display the raw pixel data as an Image.

Okay now the Photon app has an Pointer to the Server and reads the Data. (you can see it in the setImageArea() Function of my MyPhoton-class)

i now want to add a Callback to read the whole time the raw pixel data and display it.
This is the code where i create a new Photon Window:

int MyPhoton::startPhoton()
	std::cout << "startPhoton()" << std::endl;
	PhDim_t size;
	size.h = 240;
	size.w = 200;
	int n;

	std::cout << "Init()" << std::endl;
	if (PtInit(NULL) == -1)

	n = 0;
	PtSetArg(&args[n++], Pt_ARG_WINDOW_TITLE, "ImageWindow", 0);
	PtSetArg(&args[n++], Pt_ARG_DIM, &size,0);

	std::cout << "create ImageWindow()" << std::endl;
	frontWindow = PtCreateWidget(PtWindow, Pt_NO_PARENT, n, args);


	return (EXIT_SUCCESS);


And after i created a new Photon Window i add an ImageArea to the Window with the actually readed raw pixel data.

int MyPhoton::setImageArea(PtWidget_t* parent)

	std::cout << "Set ImageArea" << std::endl;

                //get the Data from the tcp Server
	const unsigned int* framePic = tcpServer->getFrame()->GetDefishedImage();

	memset(&directServerImage, 0, sizeof(PhImage_t));

	directServerImage.image = (char*) framePic;
	directServerImage.type = Pg_IMAGE_DIRECT_8888;
	directServerImage.size.h = 240;
	directServerImage.size.w = 640;
	directServerImage.alpha = 0;
	directServerImage.bpl = 5120;
	directServerImage.colors = 0;
	directServerImage.flags |= Ph_RELEASE_IMAGE_ALL;

	int n = 0;
	int imageArea_drag_cb( PtWidget_t *, void *, PtCallbackInfo_t *);
	PtCallback_t callbacks[] = { {imageArea_drag_cb, NULL} };

	PtSetArg( &args[n++], Pt_CB_IMAGEAREA_DRAG, callbacks, sizeof(callbacks)/sizeof(callbacks[0]));
	PtSetArg( &args[n++], Pt_ARG_DIM, &directServerImage.size, 0 );
	PtSetArg( &args[n++], Pt_ARG_IMAGEAREA_IMAGE, &directServerImage, sizeof(PhImage_t));

	imageArea = PtCreateWidget( PtImageArea, parent, n, args );

	return Pt_CONTINUE;

and my callback method activates when i drag the ImageArea:

int imageArea_drag_cb( PtWidget_t *w, void *data, PtCallbackInfo_t *cbInfo)

	PhImage_t* img;
	img = PxLoadImage("/home/write100.bmp",NULL);
	img->flags |= Ph_RELEASE_IMAGE_ALL;
	PtSetResource(w ,Pt_ARG_IMAGEAREA_IMAGE, img, sizeof(PhImage_t) );
	return Pt_CONTINUE;

This Code Works, but you can see that im loading an Image from an existing bitmap.

Now i want to load the image from the tcpServer in my callback.
How can i made this?
How can i get a Server Pointer which shows to the tcpServer ? :confused:

and can i made the callback to a classfunction of MyPhoton?
then i could have acces to the tcp Server, but i think thats not working.

i hope somebody understands me and can give me a hint ;)

with best regards


After you create your image widget, you will need to “realize” the widget with PtRealizeWidget().

I don’t build C++ Photon programs, but I would not use a class method as a callback.
You might however call a class method from a callback.

hey :slight_smile: thanks for ur reply :slight_smile:

i cant call a classmethod from the callback function. and when i create a new Objekt in my callback, then i have the same problem, that i dont have any Server-Pointer to give it to the new Objekt.

there must be a trick to become some data to the callback function :confused: but i dont know how :confused:

If you attach the callback with the function PtAddCallback(), you can pass a pointer to some data that will be passed to the callback in the 2nd parameter. That data could be a pointer to an object.

I don’t know why you can’t call a class method from a callback function. If you are running multiple threads you might need a mutex to protect entry to the class or the object. If you can’t figure out where the object is, I don’t think you are being creative enough.