[Carbon] CFNotificationCenter CallBack

Eddy58

Membre actif
27 Décembre 2002
134
0
Visiter le site
Bon, mes connaissances en Carbon relevants du strict nécessaire, j'ai un petit problème pour faire fonctionner la fonction Callback appelée par la fonction CFNotificationCenterAddObserver. Après tout le code d'initialisation, qui est simplement le template d'XCode à la création du projet, je crée l'observateur avec AddObserver, ensuite je poste une notification à destination d'une appli pure Cocoa elle (c'est tellement plus simple !), ensuite cette appli renvoie une notification à l'appli Carbon émettrice comme quoi les données sont bien reçus, mais voilà la fonction Callback ne m'affiche pas le printf() de test. La notification de retour est pourtant bien postée par l'appli Cocoa (j'ai vérifié avec Notification Watchers), mais dans l'immédiat je vois pas pourquoi le code test Carbon ne reçoit rien.
Est-ce que j'ai mal configuré ma fonction AddObserver ?
Ou alors est-ce que la fonction RunApplicationEventLoop() est inappropriée au contexte et bloque ainsi le Callback, donc dans ce cas que faudrait-il mettre afin d'avoir une simple attente de la notification de retour ?
Si quelqu'un connaissant Carbon a une quelconque idée, je suis preneur de toute info.

Bloc de code:
void MyCallBack(CFNotificationCenterRef center,void *observer,CFStringRef name,const void *object,CFDictionaryRef userInfo);

int main(int argc, char* argv[])
{
    IBNibRef       nibRef;
    WindowRef       window;
    
    OSStatus      err;

    // Create a Nib reference passing the name of the nib file (without the .nib extension)
    // CreateNibReference only searches into the application bundle.
    err = CreateNibReference(CFSTR("main"), &nibRef);
    require_noerr( err, CantGetNibRef );
    
    // Once the nib reference is created, set the menu bar. "MainMenu" is the name of the menu bar
    // object. This name is set in InterfaceBuilder when the nib is created.
    err = SetMenuBarFromNib(nibRef, CFSTR("MenuBar"));
    require_noerr( err, CantSetMenuBar );
    
    // Then create a window. "MainWindow" is the name of the window object. This name is set in 
    // InterfaceBuilder when the nib is created.
    err = CreateWindowFromNib(nibRef, CFSTR("MainWindow"), &window);
    require_noerr( err, CantCreateWindow );

    // We don't need the nib reference anymore.
    DisposeNibReference(nibRef);
    
    // The window was created hidden so show it.
    ShowWindow( window );

   CFNotificationCenterAddObserver(CFNotificationCenterGetDistributedCenter(),
     NULL,
     MyCallBack,
     CFSTR("ReceiptNotification"),
     NULL,
     CFNotificationSuspensionBehaviorDeliverImmediately);
   
   CFNotificationCenterPostNotification(CFNotificationCenterGetDistributedCenter(),CFSTR("SendNotification"),NULL,NULL,FALSE);

   // Call the event loop
    RunApplicationEventLoop();

CantCreateWindow:
CantSetMenuBar:
CantGetNibRef:
   return err;
}

void MyCallBack(CFNotificationCenterRef center,void *observer,CFStringRef name,const void *object,CFDictionaryRef userInfo)
{
   printf("CallBack");
}
 
Bloc de code:
CFNotificationCenterAddObserver(CFNotificationCenterGetDistributedCenter(),
     NULL,
     MyCallBack,
   [COLOR="Red"]  CFSTR("ReceiptNotification"), [/COLOR]
     NULL,
     CFNotificationSuspensionBehaviorDeliverImmediately);
   
   CFNotificationCenterPostNotification(CFNotificationCenterGetDistributedCenter(),
[COLOR="red"]CFSTR("SendNotification")[/COLOR],NULL,NULL,FALSE);
:confused: :confused:
 
La notification "SendNotification" est envoyée à l'appli Cocoa. Cette appli Cocoa renvoie ensuite la notification "ReceiptNotification", comme quoi elle a bien reçue la notification "SendNotification". La notification "ReceiptNotification" est correctement envoyée par l'appli Cocoa, j'ai testé avec du code Cocoa pour la réception et avec l'utilitaire Notification Watchers. Seulement j'ai aussi besoin de récupérer cette notification via Carbon, mais le CallBack ne me donne rien...:(