Re: Save open files on suspend
- From: "Voidcoder" <voidcoder@xxxxxxxxx>
- Date: Thu, 23 Mar 2006 12:35:34 +0100
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
Thank you Voidcoder, I will try this.
You can use PowerPolicyNotify() to send custom messages to PM.
Use PPN_OEMBASE + XXX to implement your custom messages.
The PM already has a way to send events to the registered clients toThat's correct, but can I send OEM Notifications this way?
them about the power state changes. See RequestPowerNotifications(),
CreateMsgQueue(), ReadMsgQueue() in documentation.
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
.
- Follow-Ups:
- Re: Save open files on suspend
- From: Michael Reim
- Re: Save open files on suspend
- References:
- Save open files on suspend
- From: Michael Reim
- Re: Save open files on suspend
- From: Voidcoder
- Re: Save open files on suspend
- From: Michael Reim
- Re: Save open files on suspend
- From: voidcoder
- Re: Save open files on suspend
- From: Michael Reim
- Save open files on suspend
- Prev by Date: How to add Compact Framework 2.0 to the Catalog ?
- Next by Date: Re: NMAKE : fatal error U1073: don't know how to make
- Previous by thread: Re: Save open files on suspend
- Next by thread: Re: Save open files on suspend
- Index(es):
Relevant Pages
|
|