• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Trouble accessing Objective-C++ code from a C++ thread
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Trouble accessing Objective-C++ code from a C++ thread


  • Subject: Trouble accessing Objective-C++ code from a C++ thread
  • From: JoanBa <email@hidden>
  • Date: Sun, 29 Feb 2004 18:32:51 +0100

Hi,

I'm a newbie in Objective-C++ and I've a question about reusing C++
code in MacOS X.

I've designed the graphical interface using Interface Builder, and
generating Objective-C++ code, basically a class called FlyController.
This controller drives the GUI of my application and starts several
threads ( POSIX threads ), which do the job, defined as a C++ classes.
I've followed the Apple docs about Objective-C and it works.

Now the issue. My graphical interface has a simple window with a
NSTextView object and I want to redirect all the messages from all the
threads to this window ( now I'm using standard <iostream> functions at
thread level ). I can do it easily from Objective-C++ code, but I don't
know how to write in this view from C++ code.

I've declared a member variable in the C++ class of type 'id', and when
I create an instance of the C++ class with the 'new' operator I copy
the 'self' pointer from the FlyController class to this variable, in
order to get a reference and to have access the NSTextView. It doesn't
work. I reproduce the code:

The C++ class:

file FlyUDPReceiver.h

// #import "FlyController.h" <-- if I uncomment this line I cannot
compile, see below. I don't have access
// to the FlyController Obj-C++ class !!

class FlyUDPReceiver: public Thread {
public:
FlyUDPReceiver(packetBuf *theBuf, char *host, int port, short trace,
id controller);
~FlyUDPReceiver(void);
void run(void);
(...)

private:

(...)

id mcontroller;
};

file FlyUDPReceiver.mm

FlyUDPReceiver::FlyUDPReceiver(packetBuf *theBuf, char *host, int port,
short trace, id controller) {

pool = [[NSAutoreleasePool alloc] init];

(...)

mcontroller = controller;
}

FlyUDPReceiver::~FlyUDPReceiver(void) {

(...)

[pool release];

(...)

}

void FlyUDPReceiver::run(void) {

(...)

[mcontroller appendToLog:@"FlyUDPReceiver: Starting UDP receiver"];

(...)

}

The Objective-C++ class:

file FlyController.h

#import "FlyUDPReceiver.h"
(...)

file FlyController.mm

- (IBAction)Start:(id)sender
{
(...)

// Comencem la recepcis de paquets UDP
wrec = new FlyUDPReceiver(gBuf, ipadr, wport, wtrace, self);
wrec->start();

(...)
}

- (void)appendToLog:(NSString *)message
{
(...)
}



With this code, I can compile with this warning:

/projectes/FlyMotion/codi/FlyMotion/FlyUDPReceiver.mm:142: warning:
cannot find method `-appendToLog:'; return type `id' assumed

When I run the app always crashes with the following messages:

2004-02-27 17:26:49.886 FlyMotion[2108] *** _NSAutoreleaseNoPool():
Object 0x47bd30 of class NSCFCharacterSet autoreleased with no pool in
place - just leaking
2004-02-27 17:26:49.910 FlyMotion[2108] *** _NSAutoreleaseNoPool():
Object 0x49e2c0 of class NSConcreteValue autoreleased with no pool in
place - just leaking
2004-02-27 17:26:49.925 FlyMotion[2108] *** _NSAutoreleaseNoPool():
Object 0x49e2e0 of class NSCFDictionary autoreleased with no pool in
place - just leaking
2004-02-27 17:26:49.934 FlyMotion[2108] *** _NSAutoreleaseNoPool():
Object 0x49e720 of class NSCFString autoreleased with no pool in place
- just leaking
2004-02-27 17:26:49.943 FlyMotion[2108] *** _NSAutoreleaseNoPool():
Object 0x49e4c0 of class NSCFString autoreleased with no pool in place
- just leaking
2004-02-27 17:26:49.952 FlyMotion[2108] *** _NSAutoreleaseNoPool():
Object 0x49e740 of class NSCFData autoreleased with no pool in place -
just leaking
2004-02-27 17:26:49.963 FlyMotion[2108] *** _NSAutoreleaseNoPool():
Object 0x431590 of class NSCFString autoreleased with no pool in place
- just leaking

but I'm thinking that in fact I cannot access the Obj-C++ object
FlyController simply copying an id object because there is no access
from the C++ class to the Objective-C++ class
definition/implementation. If I include an import line in the C++ class
like:

file FlyUDPReceiver.h

#import "FlyController.h"

class FlyUDPReceiver: public Thread {
(...)

I cannot compile at all:

In file included from
/projectes/FlyMotion/codi/FlyMotion/FlyUDPReceiver.h:27,
from
/projectes/FlyMotion/codi/FlyMotion/FlyUDPReceiver.mm:14:
/projectes/FlyMotion/codi/FlyMotion/FlyController.h:19: error: parse
error before `*' token

I'm completely lost. Any idea ??

Best regards,
Joan B. Altadill
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: Trouble accessing Objective-C++ code from a C++ thread
      • From: Allan Odgaard <email@hidden>
  • Prev by Date: Re: Error messages
  • Next by Date: Re: Databasing and Cocoa
  • Previous by thread: Re: When to relayout view in NSScrollView?
  • Next by thread: Re: Trouble accessing Objective-C++ code from a C++ thread
  • Index(es):
    • Date
    • Thread