getting events

Discussion in 'Mac Programming' started by skumar2011, Mar 28, 2007.

  1. macrumors newbie

    Joined:
    Dec 19, 2006
    #1
    Hi Guys,

    I have written two application on Mac,one is using carbon and another one is using cocoa. My both applications get launched and run as a process when Mac OS start because I m launching my applications from StartumItems. Now I don't want to allow any user to force quit my applications from activity monitor, if suppose user force quit the my applications at this point i want to restart the Mac machine automaticaly as soon as my applications gets quit.

    Looking for the help.

    Thanks,

    Sunil
     
  2. macrumors 6502

    Joined:
    Mar 31, 2005
    Location:
    London, England
    #2
    The only way to do this is to have each application monitor the other, and take action if it detects that the other application has quit.

    I'm not sure how to do this in Carbon, but in Cocoa's it's very easy: get the workspace notification centre from NSWorkspace and register to receive the notification called "NSWorkspaceDidTerminateApplicationNotification".
     
  3. Wes
    macrumors 68020

    Wes

    Joined:
    Jun 22, 2001
    Location:
    London
    #3
    This application sounds a lot like a virus... :confused:
     
  4. thread starter macrumors newbie

    Joined:
    Dec 19, 2006
    #4
    event notification

    thanks guys for quick reply

    in reply to the wes this is not a virus type of application

    Nutter u mean to say i have to create a thread in my application in that thread i have to continously scan my second application is there in activity monitor or not,if not then it will restart the Mac machine. This will work fine if we simply quit the application form activity monitor and get the notification through NSWorkspaceDidTerminateApplicationNotification API but if i force quit then we won't get any notification through NSWorkspaceDidTerminateApplicationNotification API.

    If I m wrong the please correct me.
     
  5. macrumors 6502

    Joined:
    Mar 31, 2005
    Location:
    London, England
    #5
    You will get a notification even if the application is force quit. I wouldn't recommend polling, that's not necessary.

    There are uses for this kind of thing that don't involve viruses! However, you may want to consider just relaunching the apps if they are quit rather than restarting the whole system.
     
  6. thread starter macrumors newbie

    Joined:
    Dec 19, 2006
    #6
    event notification

    thanks Nutter
    let me check what u said.
    u don't have any idea in carbon?
    How to implement same thing in carbon?
    as u said in cocoa it is easy to implement.

    actualy i hav developed the client and server kind of application using BSD and CFSocket and i m launching my client application through StartupItems. Whenever any particular client get disconnected ,i get the notification server side but which client got disconnect thats i don't know. I have posted this thing how to identify disconnected client on server side while using CFSocket but didn't get any reply.

    Can u suggest me any link?
     
  7. macrumors G5

    gnasher729

    Joined:
    Nov 25, 2005
    #7
    That sounds rather nasty. Trying to implement some malware that starts when the Mac is started, observes each other and restarts the Mac when one is shut down so you can't get rid of it? Good luck.
     
  8. macrumors 6502

    Joined:
    Mar 31, 2005
    Location:
    London, England
    #8
    So the two apps aren't running on the same Mac? In that case, each app will have to spawn a separate process to monitor it. I have no idea how this is done in Carbon.

    This wouldn't be very effective as malware. There's nothing to stop the user removing the applications from their startup items. I presume this is for a legitimate purpose, such as creating a server application that keeps itself running even in the event that it unexpectedly quits.
     

Share This Page