[Need Help] From ObjC++ to ObjC & C++

  • Bonjour,

    =46ew months ago, I wrote a mutlithreaded app under MacOS X Server.
    This is a ObjC++ application.

    My problem is :
    *
    Since Apple doesn't support ObjC++ code with MacOS X I don't know how
    to rewrite my application keeping the C++ source code and ObjC source code.
    *

    The facts are :
    I can't rewrite the "engine" of this software in other langage. It's in C++.
    I really need to use ObjC because I want to use DO architecture (com.
    between processes)

    The only things I know are :
    C++ can call C
    C++ can do "C linkage"
    ObjC can call C

    These "rules" should be the key to rewrite simply my application,
    but I have no idea to realise it.

    I hope you could help me to reorganize my source code (see samples).

    Here is my sample code in ObjC++

    extern "Objective-C"
    {
    #import <Foundation/Foundation.h>
    #import "threaded_app.h"
    }

    void main( int argc, char *argv[] )
          {

    NSAutoreleasePool *thePool =3D [[NSAutoreleasePool alloc] init];

    ThreadedApp *AppInThread;
    NSConnection *defaultConn =3D [NSConnection defaultConnection];

    AppInThread =3D [[ThreadedApp alloc] init];
    [defaultConn setRootObject:AppInThread];
    if ([defaultConn registerName:@"ThreadedApp"] =3D=3D NO)
    {
               NSLog(@"Unable to launch as a server -> e-mail to
    <kubernan...>");
               exit(EXIT_FAILURE);
    }
    [defaultConn runInNewThread];

    NSLog(@"Succesfully launched");
    [[NSRunLoop currentRunLoop] run];

              [thePool release];
      }

    And now theaded_app.M
    Note this is a server application (running in background); this
    server receives data from
    clients application (c.f. NSMutableDictionary), treats these data
    and sometimes sends a result.
    The communications between server and clients is based on D.O.
    (so in ObjC), but all the data process is write in C++.

    extern "Objective-C"
    {
    #import <Foundation/Foundation.h>
    #import "threaded_app.h"
    }

    // some #include

    // some #define

    @implementation ThreadedApp

    - (NSMutableDictionary *)app_process:(id) sender
    {

    NSMutableDictionary *retour_error =3D [[NSMutableDictionary alloc] init];

    NSLog(@"Request is in loop");

    // We beggan to read the "objects" sends by client
            NSString *signature =3D [sender objectForKey:@"signature_app"];
    int ln;
    lnr =3D [signature length];
    if (ln =3D=3D 0)
    {
    // If error, I send the error to the client !!!!!
                NSString *error_string =3D @"=3D=3D=3D signature_app missing =
    =3D=3D=3D";
                [retour_error setObject:error_string forKey:@"error"];
                return [[retour_error copy] autorelease];
    }

    /*------- INITIALISATION -------------------------*/
            NSNumber *type_of_demand;
            type_of_demande =3D [sender objectForKey:@"execution_mode"];
            bool learning_mode;
            learning_mode =3D [type_of_demande boolValue];

    if (learning_mode)
    /*---------------- LEARNING MODE -----------------*/
    {

    NSLog(@"LEARNING PHASE LAUNCHED");

    // some declarations

            double *array_of_input_values;
            double *array_of_output_values;

    // ObjC
            NSNumber *value1;
            value1 =3D [sender objectForKey:@"value1"];
            value =3D [value1 doubleValue];
    // C++
    cout << "value1      : " << value << endl;

    // ...
    // <SNIP>
    // ...

            array_of_input_values =3D new double[value_x];
    // value_x is a value sends by client (a NSNumber)
            array_of_output_values =3D new double[value_y];

            while (save_index < total_number_of_something)
            {
      // ...
        // some declarations
      // ...
                    for (index_array =3D 0; index_array < input_values;
    index_array++)
                    {
                    NSNumber *input_double;
                    input_double =3D [input_value objectAtIndex:save_index];
                    double value_to_read;
                    valeur_to_read =3D [input_double doubleValue];
                    array_of_input_values[index_array] =3D valeur_to_read;
                    save_index =3D save_index + 1;
                    }

      // Create instance of a C++ object
                            data[pattern_count]=3Dnew
    Pattern(input_values,foo1,foo2,array_of_input_values);
      }

    // Create the C++ Special Object
    Special_Object SOnet(value1);

    }

    As you can see, today this code mixes C++ and ObjC.

    Thanks for your help !

    --
    ------------------------------------------
    10191 Technologies (We build infernal machines, AI tools and more)
    www coming soon.
    Emails :    <kubernan...> (webmaster)
    <yellowbaby...> (our Web Diva)
    <chris...> (our "unit=E9 d'ombre")
  • > Since Apple doesn't support ObjC++ code with MacOS X I don't know how
    > to rewrite my application keeping the C++ source code and ObjC source code.

    Be sure to read the list archives before asking your questions; it was
    announced here just yesterday that Apple's posted some new tutorial info on
    this very subject. See:

    http://developer.apple.com/samplecode/Sample_Code/Platforms_and_Tools/Proje
    ct_Builder/Cocoa_With_Carbon_or_C__.htm

    --
    Rick Roe
        Webmeister & Icon Dude
        http://www.icons.cx/
  • >> Since Apple doesn't support ObjC++ code with MacOS X I don't know how
    >> to rewrite my application keeping the C++ source code and ObjC source co=
    de.
    >
    > Be sure to read the list archives before asking your questions; it was
    > announced here just yesterday that Apple's posted some new tutorial info on
    > this very subject. See:
    >
    > http://developer.apple.com/samplecode/Sample_Code/Platforms_and_Tools/Proj
    e

    > ct_Builder/Cocoa_With_Carbon_or_C__.htm
    >
    Ok... Thx a lot..I didn't see this news.
    I saw the sample source, it seems simple. But, despite of the fact i'm a new=
    bie
    in ObjC++, I could create my first application in ObC++ on MacOS X server.
    Now, in MacOS X, when i think my code using the Wrapper for C++ i can see
    small problems such as :

            int num_x;
            NSArray *number_in_x =3D [sender objectForKey:@"number_in_x"];
            num_x =3D [number_in_x count];
    // PB HERE ("new", a c++ method)
            x_count=3Dnew int[num_x]; //********** C++ *********
            int value;
            for (int i =3D 0; i < num_x; i++)
                {
               NSNumber *number_of_x_by_y;
               number_of_x_by_y =3D [number_in_x objectAtIndex:i];
      value =3D [nombre_neurones_par_couche intValue];
                    x_count[i] =3D value;
                }
    Of course i can use a wrapper for calling my C++ methods, but,
    what can i do for some functions such as "new" is this sample (or cout ?).
    Thx a lot again for your help.

    --
    ------------------------------------------
    10191 Technologies (We build infernal machines, AI tools and more)
    www coming soon.
    Emails :    <kubernan...> (webmaster)
    <yellowbaby...> (our Web Diva)
    <chris...> (our "unit=E9 d'ombre")