Re: CeRunAppAtEvent and SetSystemTime question by Jeff
Jeff
Thu Jan 13 07:36:58 CST 2005
Thanks Paul, I finally have my code working.
To answer my own question below, it does appear that you can register
multiple events for a notification. The reason I wasn't seeing it
seemed to have to do with how I was launching my test application. I
was lauching it automatically through the registry like:
[HKEY_LOCAL_MACHINE\init]
"Launch80"="RTC_Test.exe"
"Depend80"=hex:14,00
If I started it that way, i never got the event. However, if I started
it via the Target->Run Programs menu option in Platform Builder, it
executed as I expected and I got my event.
thanks for the help!
Jeff
Paul G. Tobey [eMVP] wrote:
> The time change event is one sent when the user modifies the date/time, via
> the Control Panel, for example. I'd be surprised if there wasn't some way
> to distribute that event far and wide, although I've not tried it with the
> same exact named event.
>
> Paul T.
>
> "Jeff Cooper" <jacooper@visi.com> wrote in message
> news:41e58aa3$0$1614$a1866201@visi.com...
>
>>Paul,
>>
>>Thanks for the pointer. It turns out that notifications need to have
>>shell around in addition to the Device Manager, so I needed spin on
>>IsAPIReady( SH_SHELL ). After that, my named event was registered without
>>error.
>>
>>Naturally, things still didn't work, my event never occured when the time
>>was changed.
>>
>>I noticed when I was checking out the debug logs that a driver for
>>Daylight Saving Time gets loaded after my driver and also registers for a
>>NOTIFICATION_EVENT_TIME_CHANGE event.
>>
>>I'm guessing that only one named event can be set for a particular
>>notification and since DST got there last, they get the notification.
>>
>>Does anyone know if that's a true statement?
>>
>>In my next attempt, I'll try waiting for DST to setup their named event
>>and then use OpenEvent on it. My only concern is not knowing how the
>>notifications are implmented. If two threads are waiting on the event,
>>and the event occurs, will both threads get release (i.e. SetEvent()) or
>>does only one get released (i.e. PulseEvent())?
>>
>>It's times like this that I love Open Source!
>>
>>thanks,
>>Jeff
>>
>>Paul G. Tobey [eMVP] wrote:
>>
>>>Ah, yes, I see. I have the I2C stuff in the kernel, in my case. I
>>>suppose that you could signal the driver from the kernel somehow. It
>>>seems to me that we had a discussion on this topic some time ago and I
>>>think it was I2C related too. Maybe there's something there that will
>>>point you in the right direction.
>>>
>>>I think, without any documented reason, that the Device Manager is
>>>responsible for notifications. You might try IsAPIReady(
>>>SH_DEVMGR_APIS ), or any of the other potential candidates in kfuncs.h.
>>>
>>>I think that, other than not being able to call the APIs you're trying to
>>>use so early, no, that's the basic code. You can look at the explorer
>>>shell code, dst.cpp, in the PUBLIC branch of the Windows CE source, if
>>>you want to compare what you're doing to the 'standard'.
>>>
>>>Paul T.
>>>
>>>
>>>"Jeff Cooper" <jacooper@visi.com> wrote in message
>>>news:41e45a2a$0$78851$a1866201@visi.com...
>>>
>>>
>>>>Paul,
>>>>
>>>>Thanks for the reply.
>>>>
>>>>I was thinking of modifying the OEMSetRealTime, but I had an issue that I
>>>>wasn't sure how to handle: The RTC and I2C drivers are stream drivers so
>>>>how do I make IOCTL calls from within the kernel. We don't want to put
>>>>the bus driver (I2C) in the kernel so I was investigating other solutions
>>>>when I found out about NOTIFICATION_EVENT_TIME_CHANGE.
>>>>
>>>>When is the notification system ready for use (i.e. what loads it)? Is
>>>>there any routines that call be called to check the state of the
>>>>notification system, perhaps similar to IsAPIReady()?
>>>>
>>>>Is there any reason that the approach I've taking with spinning a thread
>>>
>>>>from the RTC_Init() routine in my driver won't work?
>>>
>>>>thanks,
>>>>Jeff Cooper
>>>>
>>>>Paul G. Tobey [eMVP] wrote:
>>>>
>>>>
>>>>>Jeff,
>>>>>
>>>>>OEMSetRealTime() will be called whenever the time is changed. You don't
>>>>>have to register for anything.
>>>>>
>>>>>Paul T.
>>>>>
>>>>>"Jeff Cooper" <jeffc@logicpd.com> wrote in message
>>>>>news:ulibb2-t08.ln1@lpdlnx00.logicpd.com...
>>>>>
>>>>>
>>>>>
>>>>>>Hello,
>>>>>>
>>>>>>I'm writing a device driver for a Real Time Clock (RTC) on a I2C bus
>>>>>>attached to the processor. I'm using WinCE 4.2. I have my device
>>>>>>drivers for the I2C and RTC working fine but I have one intergration
>>>>>>issue that I'm getting stuck on:
>>>>>>
>>>>>>I need to have SetSystemTime() write the time to the RTC on the I2C bus
>>>>>>anytime the system time is changed by the user. I'm trying to use the
>>>>>>notification event, NOTIFICATION_EVENT_TIME_CHANGE, for this purpose.
>>>>>>
>>>>>>However, I'm having trouble registering the event and I'm hoping
>>>>>>someone can help me. My basic approach is that in n my drivers
>>>>>>RTC_Init() routine, I spin off a thread to keep the RTC in sync. Then
>>>>>>the thread will create a named event and call CeRunAppAtEvent with that
>>>>>>named event. Then whenever the SetSystemTime() call is made, my event
>>>>>>should be triggered.
>>>>>>
>>>>>>The beginning of my thread looks like:
>>>>>>
>>>>>> // Create a named event for notification
>>>>>> aheEvents[SYNC_TIME_CHANGE_EVENT] =
>>>>>> CreateEvent( NULL // ignored
>>>>>> ,FALSE // not manual reset
>>>>>> ,FALSE // not signaled
>>>>>> ,TEXT("RTCSync")
>>>>>> );
>>>>>> if( NULL == aheEvents[SYNC_TIME_CHANGE_EVENT] )
>>>>>> {
>>>>>> RTCMSG( ZONE_INIT | ZONE_ERROR | ZONE_WARN
>>>>>> ,(TEXT("SyncRtcTime: Error: Couldn't create event
>>>>>>(0x%08x) (line:%d)\r\n")
>>>>>> ,GetLastError()
>>>>>> ,__LINE__
>>>>>> )
>>>>>> );
>>>>>> return( -1 );
>>>>>> }
>>>>>>
>>>>>> // Make sure that the GDI is ready before we try to call
>>>>>>CeRunAppAtEvent()
>>>>>> // otherwise we'll get an exception
>>>>>> while( !IsAPIReady( SH_GDI ) && !IsAPIReady( SH_WMGR) )
>>>>>> ;
>>>>>>
>>>>>> // Set the notification to signal the named event
>>>>>> bRet = CeRunAppAtEvent(
>>>>>>TEXT("\\\\.\\Notifications\\NamedEvents\\RTCSync")
>>>>>> ,NOTIFICATION_EVENT_TIME_CHANGE
>>>>>> );
>>>>>> if( !bRet )
>>>>>> {
>>>>>> RTCMSG( ZONE_INIT | ZONE_ERROR | ZONE_WARN
>>>>>> ,(TEXT("SyncRtcTime: Error: Couldn't setup
>>>>>>notification (0x%08x) (line:%d)\r\n")
>>>>>> ,GetLastError()
>>>>>> ,__LINE__
>>>>>> )
>>>>>> );
>>>>>> CloseHandle( aheEvents[SYNC_TIME_CHANGE_EVENT] );
>>>>>> return( -1 );
>>>>>> }
>>>>>>
>>>>>>In theory I think this should work. However, I get the following error
>>>>>>messages when the thread runs:
>>>>>>
>>>>>> 4294773052 PID:41b53526 TID:81b8423e 0x81b84000:
>>>>>>NOTIFICATION::XCeRunAppAtEvent
>>>>>> 4294773054 PID:41b53526 TID:81b8423e 0x81b84000: ERROR in
>>>>>>NOTIFICATION::XCeRunAppAtEvent::Notification subsystem not yet
>>>>>>initialized
>>>>>> 4294773063 PID:1bca15e TID:81b8423e 0x81b84000: SyncRtcTime: Error:
>>>>>>Couldn't setup
>>>>>> notification (0x0000041d) (line:2620)
>>>>>>
>>>>>>So I think my problem is that I'm trying to call these functions before
>>>>>>the notification system is running. I can't find any documentation on
>>>>>>when it's ok to call these functions.
>>>>>>
>>>>>>Can anyone help me either with documentation on the notification system
>>>>>>used in CE 4.2 or suggest another approach to solving my problem.
>>>>>>
>>>>>>thanks,
>>>>>>Jeff Cooper
>>>>>>jeffc at logicpd dot com
>>>>>
>>>>>
>
>