Is there any way I can see the source code for the snapshot utility in QNX6.5

We are working on a project that has similar screen capture capabilities. Viewing the code for the snapshot utility would be very helpful. Would anyone know if this code if public somewhere?

Thanks.

To get that source code, you would need to talk with QNX. Mention the word Photon and I suspect that you will get a cold shoulder.

I’ve done work like this with Photon. If you have some questions you can email me at maschoen@pobox.com and I will try to help out.

Snapshot has some pretty sophisticated capabilities, e.g. choosing the whole screen vs. a windows vs. a user described area. If you want something simpler, something that will just grab the screen, I recall (vaguely) that there are Photon calls to do just that.

static int do_snapshot(void)
{
PhRect_t screen;
char buf[256];
size_t shsize;
pthread_attr_t attr;
int errno_save, retc = 1, destroy_needed = 1;

/* Do this little bit to allow other apps to repair themselves before
   taking the snapshot */

pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED);

if(pthread_create(NULL,&attr,wakeup_caller,(void*)getprio(0)) == EOK)
{
	int old_prio = setprio(0,1);
	sched_yield();
	setprio(0,old_prio);
}

PhWindowQueryVisible(Ph_QUERY_IG_REGION,0,PhInputGroup(NULL),&screen);

if(PhRectIntersect(&capture,&screen) && (shsize = PgReadScreenSize(&capture)))
{
	PhImage_t *img_buf;
	char shname[16];
	static int shcount = 1;

	sprintf(shname,"/snap%08lx",(getpid() << 16) ^ shcount++);
	
	if(img_buf = PgShmemCreate(shsize,shname))
	{
		PhImage_t *image = PgReadScreen(&capture,img_buf);
	
		if(image)
		{
			unsigned short *selection;

			PtGetResource(ABW_send_choice,Pt_ARG_CBOX_SEL_ITEM,&selection,0);

			PtRealizeWidget(ABW_base);

			if(*selection <= 1)
			{
				view_image(shname,shsize,img_buf);
				//
				// The view_image() function handles destruction of the
				// shared memory.
				//
				destroy_needed = 0;
			}
			else
			{
				char *choice;
	
				PtGetResource(ABW_send_choice,Pt_ARG_TEXT_STRING,&choice,0);

				if ((writeFile(image,choice)) != 0) {
                                       char graphics_buf[45];
				   PgVideoModeInfo_t ModeInfo;
			           PgDisplaySettings_t ModeSetting;

                                       if (PgGetVideoMode( &ModeSetting ))
                                          sprintf(graphics_buf, "[Couldn't get current video mode.]");
                                       else {
				      if (PgGetVideoModeInfo(ModeSetting.mode, &ModeInfo))
				         sprintf(graphics_buf, "[Couldn't get current video mode info.]");
                                          else
				         sprintf(graphics_buf, "%dx%dx%d-Bit Color", ModeInfo.width, ModeInfo.height, ModeInfo.bits_per_pixel);
                                       }
                                       sprintf(buf, "Couldn't save file.\n '%s' format does not support the %s graphics setting. Please change your graphics mode or select an alternate format to save.", choice, graphics_buf);
                                       PtNotice(ABW_base,NULL,"Error",NULL,buf,NULL,NULL,NULL,Pt_MODAL);
                                   }
			}
			
			retc = 0;
		}

		errno_save = errno;
		if (destroy_needed)
			PgShmemDestroy(img_buf);
		errno = errno_save;
	}
}

if (retc) {
	PtRealizeWidget(ABW_base);
	sprintf(buf,"Error acquiring image:\n%s",strerror(errno));
	PtNotice(ABW_base,NULL,"Error",NULL,buf,NULL,NULL,NULL,Pt_MODAL);
}
return retc;

}

Interesting thanks. Where did you get this/ is it possible that I could access the rest of the code? I’m paticularly interested in this section here:

Would you happen to have the code for this wakeup_caller function?

static void *wakeup_caller(void *data)
{
nanosleep(&MAX_TIMEOUT,NULL);
setprio(0,(int)data);
return(NULL);
}

I got the source, from QNX, year ago. NDA should prevent me from posting said code but I’m pretty sure they don’t mind posting this insignificant piece of code, of a dead product.