Beispiel #1
0
int coAttach(void)
{
    int result;
    if (coSimLibData.soc == -1)
    {
        fprintf(stderr, "trying to reattach to covise...");
        if (isServer)
        {
            result = acceptServer(0.05f);
        }
        else
        {
            result = openClient(ip.s_addr, minPort, 1);
        }

        if (result != -1)
        {
            int32 handshake = 12345;
            fprintf(stderr, "attached\n");
            sendData(&handshake, sizeof(int32));

#ifdef HAVE_GLOBUS
            {
                xsd_any *fault;
                int err, fault_type;
                getSimulationType getSimulation;
                getSimulationResponseType *getResponse;
                getSimulationResponseType_init(&getResponse);

                getSimulation.user = getenv("USER");
                getSimulation.host = getenv("HOSTNAME");
                getSimulation.port = result;
                if ((err = SimulationPortType_getSimulation_epr(client_handle,
                                                                epr,
                                                                &getSimulation,
                                                                &getResponse,
                                                                (SimulationPortType_getSimulation_fault_t *)&fault_type,
                                                                &fault)) == GLOBUS_SUCCESS)
                {
                    if (getResponse != 0)
                    {
                        SimulationType sim = getResponse->result;

                        setStatusType setStatus;
                        setStatusResponseType *statusResponse;
                        setStatusResponseType_init(&statusResponse);

                        setStatus.user = sim.user;
                        setStatus.id = sim.id;
                        setStatus.status = 0; // attach

                        if ((err = SimulationPortType_setStatus_epr(client_handle,
                                                                    epr,
                                                                    &setStatus,
                                                                    &statusResponse,
                                                                    (SimulationPortType_setStatus_fault_t *)&fault_type,
                                                                    &fault)) == GLOBUS_SUCCESS)
                        {
                            fprintf(stderr, "globus set status: %d\n", statusResponse->result);
                        }
                        else
                        {
                            fprintf(stderr, "globus error %d: [%s] \n", err, globus_object_printable_to_string(globus_error_get(err)));
                        }
                        setStatusResponseType_destroy(statusResponse);
                    }
                }
                else
                {
                    fprintf(stderr, "globus error %d: [%s] \n", err, globus_object_printable_to_string(globus_error_get(err)));
                }
                getSimulationResponseType_destroy(getResponse);
            }
#endif

            return 1;
        }
        else
        {
            fprintf(stderr, "failed\n");
        }
    }
    return 0;
}
Beispiel #2
0
int coInitConnect()
{
    const char *envStr;
    char env[256], *portStr;
    float timeout;
    int32 handshake;
    int port;

    coSimLibData.soc = -1;

#if !(defined(WIN32) || defined(WIN64))
    /* we do our own handling of broken pipes */
    signal(SIGPIPE, SIG_IGN);
#endif

    /* get environment: if variable not set, exit with error-code */
    envStr = getenv("CO_SIMLIB_CONN");
    fprintf(stdout, "SIMLIB: %s\n", envStr);
    if ((!envStr) || (strlen(envStr) > 255))
        return -1;

    /* Client connection */
    strcpy(env, envStr);
    if (*env == 'C')
    {
        size_t retval;
        isServer = 0;
        /* get adress and port */
        portStr = strchr(env, '/');
        if (!portStr)
        {
            fprintf(stderr, "error parsing environment variable [%s]\n", env);
            return -1;
        }
        *portStr = '\0';
        portStr++;
        retval = sscanf(portStr, "%d_%f_%d", &minPort, &timeout, &coSimLibData.verbose);
        if (retval != 3)
        {
            fprintf(stderr, "coInitConnect: sscanf failed\n");
            return -1;
        }
        if (minPort < 1024 || minPort > 32767)
            return -1;

#ifndef WIN32
        if (!inet_aton(env + 2, &ip))
            return -1;
#else
        ip.s_addr = inet_addr(env + 2);
        if (ip.s_addr == -1)
            return -1;
#endif
        if (coSimLibData.verbose > 0)
            fprintf(stderr, " Starting Client to %s Port %d with %f sec timeout\n",
                    inet_ntoa(ip), minPort, timeout);

        /* we try to connect now */
        if ((port = openClient(ip.s_addr, minPort, timeout)) < 0)
            return -1;
    }

    /* Server connection */
    else if (*env == 'S')
    {
        size_t retval;
        isServer = 1;
        /* get adress and port */
        portStr = strchr(env, ':');
        if (!portStr)
        {
            fprintf(stderr, "error parsing environment variable [%s]\n", env);
            return -1;
        }
        *portStr = '\0';
        portStr++;
        retval = sscanf(portStr, "%d-%d_%f_%d", &minPort, &maxPort, &timeout, &coSimLibData.verbose);
        if (retval != 4)
        {
            fprintf(stderr, "coInitConnect: sscanf failed\n");
            return -1;
        }

        if (minPort < 1024 || minPort > 32767 || maxPort < 1024 || maxPort > 32767)
            return -1;

        /* we open and wait for the other side to connect */
        if ((port = openServer(minPort, maxPort)) < 0)
        {
            fprintf(stderr, "could not open server\n");
            return -1;
        }

        if (acceptServer(timeout) < 0)
        {
            fprintf(stderr, "could not accept server\n");
            return -1;
        }
    }
    /* Neither Client nor Server = ERROR */
    else
        return -1;

    /* Handshake: send 12345 to other side, so they might determine byte-swapping */
    handshake = 12345;
    sendData(&handshake, sizeof(int32));

#ifdef HAVE_GLOBUS
    {
        globus_result_t result = GLOBUS_SUCCESS;
        xsd_any *fault;
        int err, fault_type;
        fprintf(stderr, "activate globus modules\n");
        globus_module_activate(GLOBUS_COMMON_MODULE);
        globus_module_activate(GLOBUS_SOAP_MESSAGE_MODULE);
        registerSimulationType regSimulation;
        registerSimulationResponseType *regResponse;
        registerSimulationResponseType_init(&regResponse);
        globus_soap_message_attr_init(&message_attr);
        globus_soap_message_attr_set(message_attr, GLOBUS_SOAP_MESSAGE_AUTHZ_METHOD_KEY,
                                     NULL, NULL,
                                     (void *)GLOBUS_SOAP_MESSAGE_AUTHZ_HOST);
        globus_soap_message_attr_set(message_attr, GLOBUS_SOAP_MESSAGE_AUTH_PROTECTION_KEY,
                                     NULL, NULL,
                                     (void *)GLOBUS_SOAP_MESSAGE_AUTH_PROTECTION_PRIVACY);
        if ((result = SimulationService_client_init(&client_handle, message_attr, NULL)) == GLOBUS_SUCCESS)
        {
            char hostname[128];
            struct passwd *user = getpwuid(getuid());

            gethostname(hostname, 127);
            fprintf(stderr, "globus simulation client initialized\n");

            regSimulation.user = user->pw_name;
            regSimulation.host = hostname;
            regSimulation.port = port;
            regSimulation.name = "Fenfloss";
            fprintf(stderr, "globus regSimulation: [%s] [%s] [%d] [%s]\n", regSimulation.user, regSimulation.host, regSimulation.port, regSimulation.name);
            wsa_EndpointReferenceType_init(&epr);
            wsa_AttributedURI_init_contents(&epr->Address);
            xsd_anyURI_init_contents_cstr(&epr->Address.base_value,
                                          globus_common_create_string(getenv("GLOBUS_SIMULATIONSERVICE")));
            fprintf(stderr, " [%s]\n", getenv("GLOBUS_SIMULATIONSERVICE"));
            if ((err = SimulationPortType_registerSimulation_epr(client_handle,
                                                                 epr,
                                                                 &regSimulation,
                                                                 &regResponse,
                                                                 (SimulationPortType_registerSimulation_fault_t *)&fault_type,
                                                                 &fault)) == GLOBUS_SUCCESS)
            {
                SimulationType r = regResponse->result;

                simulationID = r.id;
            }
            else
            {
                fprintf(stderr, "globus error %d: [%s] \n", err, globus_object_printable_to_string(globus_error_get(err)));
            }
        }
        else
        {
            fprintf(stderr, "globus error %d: [%s] \n", result, globus_object_printable_to_string(globus_error_get(result)));
        }
        registerSimulationResponseType_destroy(regResponse);
    }
#endif
    return 0;
}
Beispiel #3
0
int coInitConnect()
{
   const char *envStr;
   char env[256],*portStr;
   int minPort,maxPort;
   struct in_addr ip;
   float timeout;
   
   coSimLibData.soc = -1;
   
   /* we do our own handling of broken pipes */
   signal(SIGPIPE,SIG_IGN);
  
   /* get environment: if variable not set, exit with error-code */
   envStr=getenv("CO_SIMLIB_CONN");
   if ((!envStr)||(strlen(envStr)>255)) 
      return -1;
   
   /* Client connection */
   strcpy(env,envStr);
   if (*env=='C')
   {
      /* get adress and port */
      portStr  = strchr(env,'/');
      *portStr = '\0';
      portStr++;
      sscanf(portStr,"%d,%f,%d",&minPort,&timeout,&coSimLibData.verbose);
      if ( minPort<1024 || minPort>32767 )  return -1;
      if (!inet_aton(env+2,&ip)) return -1;
      
      if (coSimLibData.verbose>0)
         fprintf(stderr," Starting Client to %s Port %d with %f sec timeout\n",
                         inet_ntoa(ip),minPort,timeout);
      
      /* we try to connect now */
      if (openClient(ip.s_addr,minPort,timeout))
         return -1;
   }
   
   /* Server connection */
   else if (*env=='S')
   {
      /* get adress and port */
      portStr  = strchr(env,'/');
      *portStr = '\0';
      portStr++;
      sscanf(portStr,"%d-%d,%f,%d",&minPort,&maxPort,&timeout,&coSimLibData.verbose);
      if (    minPort<1024 || minPort>32767
           || maxPort<1024 || maxPort>32767 )  return -1;
      if (!inet_aton(env+2,&ip)) return -1;

      if (coSimLibData.verbose>0)
         fprintf(stderr," Starting Server to %s Port %d-%d with %f sec timeout\n",
                         inet_ntoa(ip),minPort,maxPort,timeout);
      
      /* we open and wait for the other side to connect */
      if ( openServer(minPort,maxPort) || acceptServer(timeout) )
         return -1;
      
   }
   
   /* Neither Client nor Server = ERROR */
   else
      return -1;
   
   return 0;
}