views:

468

answers:

2

I'm converting a Carbon app to a Cocoa app and I can't find the Cocoa equivalent for:

UpdateSystemActivity(UsrActivity);

Any Mac people out there care to point me in the right direction? Thanks.

UPDATE: I'm building 64bit. Building 32bit works fine, but I get symbol not declared in this scope errors for UpdateSystemActivity (and others) when I build for 64bit.

UPDATE2: I'm importing the following:

#import <Cocoa/Cocoa.h>
#import <Carbon/Carbon.h>
#import <OpenGL/CGLMacro.h>

Is there some other thing I need to import when building 64bit?

UPDATE3: Adding #import <CoreServices/CoreServices.h> did not help. I still get compiler errors telling me UpdateSystemActivity and UsrActivity was not declared in this scope.

UPDATE4: Okay, file not found on OSServices/Power.h. I'm building against the 10.5 SDK and a quick search shows:

$ pwd
/Developer/SDKs
$ find . -name Power.h
./MacOSX10.3.9.sdk/Developer/Headers/CFMCarbon/OSServices/Power.h
./MacOSX10.3.9.sdk/Developer/Headers/CFMCarbon/Power.h
./MacOSX10.3.9.sdk/Developer/Headers/FlatCarbon/Power.h
./MacOSX10.3.9.sdk/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/OSServices.framework/Versions/A/Headers/Power.h

./MacOSX10.4u.sdk/Developer/Headers/CFMCarbon/OSServices/Power.h
./MacOSX10.4u.sdk/Developer/Headers/CFMCarbon/Power.h
./MacOSX10.4u.sdk/Developer/Headers/FlatCarbon/Power.h
./MacOSX10.4u.sdk/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/OSServices.framework/Versions/A/Headers/Power.h

./MacOSX10.5.sdk/Developer/Headers/FlatCarbon/Power.h
./MacOSX10.5.sdk/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/OSServices.framework/Versions/A/Headers/Power.h

Yet I get:

Mac.mm:6:29: error: OSServices/Power.h: No such file or directory
Mac.mm:6:29: error: OSServices/Power.h: No such file or directory
+2  A: 

You should still be able to call UpdateSystemActivity from within your Cocoa app -- it has not been marked deprecated.

The documentation for the API specifies importing CoreServices/CoreServices.h to get the API -- however hunting through the headers (notably in OSServices/OSServices.h) shows that the file is omitted in a 64bit environment. Nevertheless, there are sections of Power.h (where UpdateSystemActivity is defined) that are turned off for 64bits, and UpdateSystemActivity is not one of them.

In light of that, try to #import <OSServices/Power.h> directly and see if that works. (You'll have to include the CoreServices framework in your project for the header to be found as well.)

fbrereto
I am lead to believe that Carbon itself is deprecated with 64bit. I am building a 64bit app.
jeffamaphone
You are led to believe semi-incorrectly. Bits of Carbon, most notably HIServices, do not exist in 64-bit. Other bits have been redefined as non-Carbon (e.g. the File Manager, which is now considered a “core component” unrelated to Carbon despite living in CarbonCore.framework). If you can compile and link code using UpdateSystemActivity() in 64-bit, it is unaffected.
Ahruman
Ah, but I cannot compile a link. 32bit compiles, but 64bit says "I know not this symbol UpdateSystemActivity; forsooth, lead me to it." And nothing has changed in what I am including.
jeffamaphone
What framework are you expecting it to be in? The docs say it should be a part of CoreServices.
fbrereto
See updates in original question.
jeffamaphone
I appreciate your continued efforts on this topic, btw. Thanks.
jeffamaphone
sure thing :) I'm getting quite curious to see if this API really is available for 64bits, as they claim it to be but aren't making it easy to use!
fbrereto
Ran out of time today; will pick it up again tomorrow and let you know if works.
jeffamaphone
Yes you can still call `UpdateSystemActivity` but it seems that it doesn't have the desired effect in 64-bit apps (the screen still dims or screen saver activated).
adib
A: 

The issue here appears to be the line in OSServices.h that excludes Power.h if __LP64__ is defined. When building 64 bit on 10.5 UpdateSystemActivity is indeed undefined.

The good news is that the symbol does actually exist in CoreServices.framework. There are two ways to get access to it.

  1. Forward declare it: extern "C" OSErr UpdateSystemActivity(UInt8);
  2. Explicitly include Power.h, which you tried. The issue with your attempt is that OSServices/ doesn't find it's way into the search path. You can include it like so: #import </Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/CoreServices.framework/Frameworks/OSServices.framework/Headers/Power.h>

I don't have a copy of SnowLeopard handy, but the next thing to do would be to check if it's fixed there. If it isn't, file a RADAR as this is clearly an SDK bug.

Dan McCormick
UpdateSystemActivity() in the Power.h header is indeed back for 64-bit apps in the 10.6 SDK. So it would appear that the omission was unintentional, and UpdateSystemActivity() is still supported for use in preventing idle sleep as described in http://developer.apple.com/mac/library/qa/qa2004/qa1160.html.Just use Xcode's "Open quickly" to get to Power.h, and copy the function declaration and the activity type enum to your own workaround header.
natevw
natevw: Even that shouldn't be necessary anymore. Simply #including `<CoreServices/CoreServices.h>` should do it, since the #include of Power.h is no longer covered by an `#if !__LP64__` line.
Peter Hosey