Re: Save open files on suspend



Do you mean you don't get any messages at all? Then your are
doing something wrong. Have a look at this sample app:

WINCE500\PUBLIC\COMMON\OAK\DRIVERS\PM\TEST\MON\

You have to tweak listener thread priority (not the sender
thread, ie. PM) in order to receive SUSPEND notification
before the system is actually turned off.

Something like this:


CeSetThreadPriority(GetCurrentThread(), 50);

while (TRUE)
{
WaitForSingleObject(hMsgQueue, INFINITE);
if (ReadMsgQueue(hMsgQueue, ...))
{
...
}
}

Also put a DebugBreak in PM to verify whether the PBT_TRANSITION->
POWER_STATE_SUSPEND notification is really sent (the message written
to the MsgQueue).


Btw are your applications GUI based? In that case it should be even
easy. All you need is just to broadcast a custom message to all
toop-level windows in the system, so that your applications
can receive this message and save the data. You will need only
one extra line in your PlatformSetSystemPowerState
function.

#define WM_SUSPEND (WM_USER + xxx)


In your PlatformSetSystemPowerState repace the following lines:

// Start the process of suspending GWES
if(gfGwesReady) {
fWantStartupScreen = gpfnGwesPowerDown();
}

with:

// Start the process of suspending GWES
if(gfGwesReady) {
SendMessage(HWND_BROADCAST, WM_SUSPEND, 0, 0);
fWantStartupScreen = gpfnGwesPowerDown();
}


This code is called only when the system is about to suspend,
and GWES is still live at this point, so your custom message
will reach the applications.



"Michael Reim" <nospamreim@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:OVKFNZmTGHA.1868@xxxxxxxxxxxxxxxxxxxxxxx
Hello voidcoder,

thank you for this very valuable information.

PowerPolicyNotify(PPN_OEMBASE) is working. The application can now
register and deregister to the power manager.

But unfortunatly the notification message through ReadMsgQue doesn't work.
Even if I put a
CeSetThreadPriority(GetCurrentThread(), 249);
Sleep(0);
in front of WaitForSingleObject in power manager.
The application doesn't get any notification.

Do you know why?

--
Michael Reim
reim AT helmut-fischer DOT de


"voidcoder" <voidcoder@xxxxxxxxx> schrieb im Newsbeitrag news:%23At5B6fTGHA.1672@xxxxxxxxxxxxxxxxxxxxxxx
Yes, PM does not block until the power notification messages
have been read from the MsgQueue. So in case of power-off or
suspend your MsgQueue reader thread will not get the message
unless it is running at very high priority. Anyway, even you get
the message before the power transition actually started,
I'm not aware about any way to block the power transition
from application to perform some addition actions, eg.
save unsaved data etc.

One possible solution (not the best, but at least you don't need any
special API or serious changes in PM / apps to get it working) is to use a
shared event object to acknowledge the suspend transition by application.

For example you can replace your "SendNotification" function

WINCE500\PUBLIC\COMMON\OAK\DRIVERS\PM\MDD\pmnotify.cpp

with something like this:


VOID SendNotification(PPOWER_NOTIFICATION ppn, PPOWER_BROADCAST ppb, DWORD dwLen)
{
HANDLE hAckEvent = NULL;

if (ppb->Message == PBT_TRANSITION && ppb->Flags == POWER_STATE_SUSPEND)
{
TCHAR name[ 32 ];

wsprintf(name, _T("Ack_Event_For_Process_%08X"), (DWORD)ppn->hOwner);
hAckEvent = CreateEvent(NULL, FALSE, FALSE, name);
}

if (WriteMsgQueue(ppn->hMsgQ, ppb, dwLen, 0, 0))
{
if (hAckEvent)
WaitForSingleObject(hAckEvent, Some_Maximum_Timeout_To_Save_Unsaved_Data);
}

if (hAckEvent)
CloseHandle(hAckEvent);
}


And your application:


if (ReadMsgQue(...))
{
if (msg->Message == PBT_TRANSITION && msg->Flags == POWER_STATE_SUSPEND)
{
HANDLE hAckEvent;
TCHAR name[ 32 ];

SaveUnsavedData(); // Save any unsaved data ...

wsprintf(name, _T("Ack_Event_For_Process_%08X"), (DWORD)GetCurrentProcess());
hAckEvent = OpenEvent(EVENT_ALL_ACCESS, FALSE, name);

if (hAckEvent)
{
SetEvent(hAckEvent); // Ack the transition
CloseHandle(hAckEvent);
}
}
}










poll the power notifications
MsgQueue status once the POWER_STATE_SUSPEND
or POWER_STATE_OFF message has been pushed
to MsgQueue. You can use GetMsgQueueInfo to
poll the number of queue readers and block until
the reader counter doesn't reach zero, ie. all the
clients got the power-off notification, saved the
unsaved data and called






"Michael Reim" <nospamreim@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:ueqCWHcTGHA.4864@xxxxxxxxxxxxxxxxxxxxxxx

"Voidcoder" <voidcoder@xxxxxxxxx> schrieb im Newsbeitrag news:Ob6hinbTGHA.5172@xxxxxxxxxxxxxxxxxxxxxxx

You can use PowerPolicyNotify() to send custom messages to PM.
Use PPN_OEMBASE + XXX to implement your custom messages.
Thank you Voidcoder, I will try this.

The PM already has a way to send events to the registered clients to
them about the power state changes. See RequestPowerNotifications(),
CreateMsgQueue(), ReadMsgQueue() in documentation.
That's correct, but can I send OEM Notifications this way?
I already tried to get a power down message (PBT_TRANSITION) with ReadMsgQueue, but there is none.
It seems that the system is turned off before this message reaches the application.
Do you know, if it's allowed to send this message earlier from power manager
or to wait until this message reaches the application?

--
Michael Reim
reim AT helmut-fischer DOT de








.



Relevant Pages

  • Re: Save open files on suspend
    ... But unfortunatly the notification message through ReadMsgQue doesn't work. ... in front of WaitForSingleObject in power manager. ... HANDLE hAckEvent = NULL; ... CreateMsgQueue, ReadMsgQueue() in documentation. ...
    (microsoft.public.windowsce.platbuilder)
  • Re: PowerOff & PowerOn message
    ... you can register to receive notification from the Power ... Manager. ... The states are called 'suspend' and 'resume' (rather than off and ...
    (microsoft.public.pocketpc.developer)
  • Re: Fast Start-up
    ... you could theoretically use information in RAM to make a decision on ... CE does not define the power of the board in suspend, ... Most of the boot time and resume time is in the OEM code. ...
    (microsoft.public.windowsce.embedded)
  • Re: General network driver suspend/resume (was e1000 carrier related)
    ... 7.3* version of the driver from sourceforge. ... Changing this to bring up the link would make the card start to consume lots more power, which would automatically suck enormously for anyone using a laptop. ... Perhaps this needs to be fixed upstream in pci_save_state for msi devices, but the api for msi is not capable of detecting this atm. ...
    (Linux-Kernel)
  • Re: SendMessage (in secondary thread) freezes application GUI thre
    ... power left, the application stopped hanging... ... Then, in the non-UI thread, check the flag. ... queue and, again, the third thread will process that. ... will probably suspend before the about-to-suspend message gets to the UI ...
    (microsoft.public.windowsce.app.development)