Esempio n. 1
0
static void
on_address_resolved(uv_getaddrinfo_t *resolver,
                    int status,
                    struct addrinfo *result)
{
    rig_pb_stream_t *stream = rut_container_of(resolver, stream, resolver);
    uv_loop_t *loop = rut_uv_shell_get_loop(stream->shell);
    char ip_address[17] = {'\0'};

    c_return_if_fail(stream->resolving);

    if (status < 0) {
        c_warning("Failed to resolve slave address \"%s\": %s",
                  stream->hostname, uv_strerror(status));

        rut_closure_list_invoke(&stream->on_error_closures,
                                rig_pb_stream_callback_t,
                                stream);

        /* NB: we were at least keeping the stream alive while
         * waiting for the resolve request to finish... */
        stream->resolving = false;
        rut_object_unref(stream);

        return;
    }

    uv_ip4_name((struct sockaddr_in*)result->ai_addr, ip_address, 16);
    c_message("stream: Resolved address of \"%s\" = %s",
              stream->hostname, ip_address);

    uv_tcp_init(loop, &stream->tcp.socket);
    stream->tcp.socket.data = stream;

    /* NB: we took a reference to keep the stream alive while
     * resolving the address, so conceptually we are now handing
     * the reference over to keep the stream alive while waiting
     * for it to connect... */
    stream->resolving = false;
    stream->connecting = true;

    stream->connection_request.data = stream;
    uv_tcp_connect(&stream->connection_request,
                   &stream->tcp.socket,
                   result->ai_addr,
                   on_connect);

    uv_freeaddrinfo(result);
}
Esempio n. 2
0
/* Function Definitions */
void OFDMbits2letters(const emlrtStack *sp, const boolean_T bits_data[560],
                      const int32_T bits_size[2], real_T Letters_data[80],
                      int32_T Letters_size[1])
{
  real_T a;
  int32_T i32;
  int32_T i33;
  boolean_T p;
  const mxArray *y;
  static const int32_T iv237[2] = { 1, 28 };

  const mxArray *m43;
  char_T cv284[28];
  int32_T i;
  static const char_T cv285[28] = { 'C', 'o', 'd', 'e', 'r', ':', 'M', 'A', 'T',
    'L', 'A', 'B', ':', 'N', 'o', 'n', 'I', 'n', 't', 'e', 'g', 'e', 'r', 'I',
    'n', 'p', 'u', 't' };

  const mxArray *b_y;
  const mxArray *c_y;
  int32_T maxdimlen;
  boolean_T y_data[560];
  const mxArray *d_y;
  static const int32_T iv238[2] = { 1, 40 };

  char_T cv286[40];
  static const char_T cv287[40] = { 'C', 'o', 'd', 'e', 'r', ':', 'M', 'A', 'T',
    'L', 'A', 'B', ':', 'g', 'e', 't', 'R', 'e', 's', 'h', 'a', 'p', 'e', 'D',
    'i', 'm', 's', '_', 'n', 'o', 't', 'S', 'a', 'm', 'e', 'N', 'u', 'm', 'e',
    'l' };

  boolean_T b_bits_data[560];
  char_T s[7];
  int32_T exitg1;
  const mxArray *e_y;
  static const int32_T iv239[2] = { 1, 34 };

  char_T cv288[34];
  static const char_T cv289[34] = { 'M', 'A', 'T', 'L', 'A', 'B', ':', 'b', 'i',
    'n', '2', 'd', 'e', 'c', ':', 'I', 'l', 'l', 'e', 'g', 'a', 'l', 'B', 'i',
    'n', 'a', 'r', 'y', 'S', 't', 'r', 'i', 'n', 'g' };

  real_T varargin_1;
  real_T p2;
  emlrtStack st;
  emlrtStack b_st;
  emlrtStack c_st;
  emlrtStack d_st;
  emlrtStack e_st;
  st.prev = sp;
  st.tls = sp->tls;
  b_st.prev = &st;
  b_st.tls = st.tls;
  c_st.prev = &b_st;
  c_st.tls = b_st.tls;
  d_st.prev = &b_st;
  d_st.tls = b_st.tls;
  e_st.prev = &st;
  e_st.tls = st.tls;

  /*  OFDMbits2letters: Convert input bits from a double array to ascii */
  /*  integers, which can be converted to letters by the char() function */
  /*  Make input into column */
  /* Trim extra bits */
  st.site = &qab_emlrtRSI;
  st.site = &qab_emlrtRSI;
  b_st.site = &m_emlrtRSI;
  c_st.site = &n_emlrtRSI;
  a = (real_T)(bits_size[0] * bits_size[1]) / 7.0;
  st.site = &qab_emlrtRSI;
  b_floor(&a);
  st.site = &qab_emlrtRSI;
  a *= 7.0;
  if (1.0 > a) {
    i32 = 0;
  } else {
    i32 = bits_size[0] * bits_size[1];
    emlrtDynamicBoundsCheckFastR2012b(1, 1, i32, &rb_emlrtBCI, sp);
    i32 = bits_size[0] * bits_size[1];
    i33 = (int32_T)a;
    i32 = emlrtDynamicBoundsCheckFastR2012b(i33, 1, i32, &rb_emlrtBCI, sp);
  }

  emlrtVectorVectorIndexCheckR2012b(bits_size[0] * bits_size[1], 1, 1, i32,
    &x_emlrtECI, sp);

  /* Shape into letters */
  st.site = &rab_emlrtRSI;
  st.site = &rab_emlrtRSI;
  b_st.site = &m_emlrtRSI;
  c_st.site = &n_emlrtRSI;
  a = (real_T)i32 / 7.0;
  st.site = &rab_emlrtRSI;
  b_st.site = &tab_emlrtRSI;
  c_st.site = &uab_emlrtRSI;
  if (a != muDoubleScalarFloor(a)) {
    p = FALSE;
  } else {
    p = TRUE;
  }

  if (p) {
    c_st.site = &uab_emlrtRSI;
    p = TRUE;
  } else {
    p = FALSE;
  }

  if (p) {
  } else {
    y = NULL;
    m43 = mxCreateCharArray(2, iv237);
    for (i = 0; i < 28; i++) {
      cv284[i] = cv285[i];
    }

    emlrtInitCharArrayR2013a(&b_st, 28, m43, cv284);
    emlrtAssign(&y, m43);
    b_y = NULL;
    m43 = mxCreateNumericMatrix(1, 1, mxINT32_CLASS, mxREAL);
    *(int32_T *)mxGetData(m43) = MIN_int32_T;
    emlrtAssign(&b_y, m43);
    c_y = NULL;
    m43 = mxCreateNumericMatrix(1, 1, mxINT32_CLASS, mxREAL);
    *(int32_T *)mxGetData(m43) = MAX_int32_T;
    emlrtAssign(&c_y, m43);
    c_st.site = &uab_emlrtRSI;
    d_st.site = &bcb_emlrtRSI;
    c_error(&c_st, c_message(&d_st, y, b_y, c_y, &ac_emlrtMCI), &bc_emlrtMCI);
  }

  c_st.site = &ny_emlrtRSI;
  c_st.site = &ny_emlrtRSI;
  b_st.site = &ky_emlrtRSI;
  c_st.site = &af_emlrtRSI;
  maxdimlen = i32;
  if (1 > i32) {
    maxdimlen = 1;
  }

  b_st.site = &ky_emlrtRSI;
  c_st.site = &af_emlrtRSI;
  if (i32 < maxdimlen) {
  } else {
    maxdimlen = i32;
  }

  if (7 > maxdimlen) {
    b_st.site = &jy_emlrtRSI;
    c_eml_error(&b_st);
  }

  if ((int8_T)(int32_T)a > maxdimlen) {
    b_st.site = &jy_emlrtRSI;
    c_eml_error(&b_st);
  }

  b_st.site = &iy_emlrtRSI;
  c_st.site = &v_emlrtRSI;
  if (i32 == 7 * (int32_T)a) {
  } else {
    d_y = NULL;
    m43 = mxCreateCharArray(2, iv238);
    for (i = 0; i < 40; i++) {
      cv286[i] = cv287[i];
    }

    emlrtInitCharArrayR2013a(&st, 40, m43, cv286);
    emlrtAssign(&d_y, m43);
    b_st.site = &iy_emlrtRSI;
    e_st.site = &rbb_emlrtRSI;
    c_error(&b_st, b_message(&e_st, d_y, &tb_emlrtMCI), &ub_emlrtMCI);
  }

  b_st.site = &hy_emlrtRSI;
  c_st.site = &dg_emlrtRSI;
  for (maxdimlen = 0; maxdimlen + 1 <= i32; maxdimlen++) {
    y_data[maxdimlen] = bits_data[maxdimlen];
  }

  for (i32 = 0; i32 < 7; i32++) {
    maxdimlen = (int32_T)a;
    for (i33 = 0; i33 < maxdimlen; i33++) {
      b_bits_data[i33 + (int32_T)a * i32] = y_data[i32 + 7 * i33];
    }
  }

  /* Convert bits to letters */
  Letters_size[0] = (int32_T)a;
  maxdimlen = (int32_T)a;
  for (i32 = 0; i32 < maxdimlen; i32++) {
    Letters_data[i32] = 0.0;
  }

  i = 0;
  while (i <= (int32_T)a - 1) {
    st.site = &sab_emlrtRSI;
    i32 = (int32_T)a;
    i33 = 1 + i;
    emlrtDynamicBoundsCheckFastR2012b(i33, 1, i32, &qb_emlrtBCI, &st);
    b_st.site = &of_emlrtRSI;
    b_st.site = &vab_emlrtRSI;
    for (maxdimlen = 0; maxdimlen < 7; maxdimlen++) {
      s[maxdimlen] = '0';
      if (b_bits_data[i + (int32_T)a * maxdimlen]) {
        s[maxdimlen] = '1';
      }
    }

    st.site = &sab_emlrtRSI;
    b_st.site = &wab_emlrtRSI;
    maxdimlen = 0;
    do {
      exitg1 = 0;
      if (maxdimlen < 7) {
        if ((s[maxdimlen] != '0') && (s[maxdimlen] != '1')) {
          p = FALSE;
          exitg1 = 1;
        } else {
          maxdimlen++;
        }
      } else {
        p = TRUE;
        exitg1 = 1;
      }
    } while (exitg1 == 0);

    if (p) {
    } else {
      e_y = NULL;
      m43 = mxCreateCharArray(2, iv239);
      for (maxdimlen = 0; maxdimlen < 34; maxdimlen++) {
        cv288[maxdimlen] = cv289[maxdimlen];
      }

      emlrtInitCharArrayR2013a(&st, 34, m43, cv288);
      emlrtAssign(&e_y, m43);
      b_st.site = &wab_emlrtRSI;
      e_st.site = &qbb_emlrtRSI;
      c_error(&b_st, b_message(&e_st, e_y, &cc_emlrtMCI), &dc_emlrtMCI);
    }

    b_st.site = &xab_emlrtRSI;
    varargin_1 = 0.0;
    p2 = 1.0;
    for (maxdimlen = 0; maxdimlen < 7; maxdimlen++) {
      if (s[6 - maxdimlen] == '1') {
        varargin_1 += p2;
      }

      p2 += p2;
    }

    st.site = &sab_emlrtRSI;
    i32 = (int32_T)varargin_1;
    emlrtDynamicBoundsCheckFastR2012b(i32, 0, 255, &emlrtBCI, &st);
    i32 = (int32_T)a;
    i33 = 1 + i;
    Letters_data[emlrtDynamicBoundsCheckFastR2012b(i33, 1, i32, &sb_emlrtBCI, sp)
      - 1] = (int8_T)varargin_1;
    i++;
    emlrtBreakCheckFastR2012b(emlrtBreakCheckR2012bFlagVar, sp);
  }
}
Esempio n. 3
0
void
_cg_glsl_shader_set_source_with_boilerplate(cg_device_t *dev,
                                            GLuint shader_gl_handle,
                                            GLenum shader_gl_type,
                                            GLsizei count_in,
                                            const char **strings_in,
                                            const GLint *lengths_in)
{
    const char *vertex_boilerplate;
    const char *fragment_boilerplate;

    const char **strings = c_alloca(sizeof(char *) * (count_in + 6));
    GLint *lengths = c_alloca(sizeof(GLint) * (count_in + 6));
    char *version_string;
    int count = 0;

    vertex_boilerplate = _CG_VERTEX_SHADER_BOILERPLATE;
    fragment_boilerplate = _CG_FRAGMENT_SHADER_BOILERPLATE;

    version_string =
        c_strdup_printf("#version %i\n\n", dev->glsl_version_to_use);

    strings[count] = version_string;
    lengths[count++] = -1;

    if (_cg_has_private_feature(dev, CG_PRIVATE_FEATURE_GL_EMBEDDED) &&
        cg_has_feature(dev, CG_FEATURE_ID_TEXTURE_3D)) {
        static const char texture_3d_extension[] =
            "#extension GL_OES_texture_3D : enable\n";
        strings[count] = texture_3d_extension;
        lengths[count++] = sizeof(texture_3d_extension) - 1;
    }

    if (shader_gl_type == GL_VERTEX_SHADER) {
        if (dev->glsl_version_to_use < 130) {
            strings[count] = "#define in attribute\n"
                             "#define out varying\n";
            lengths[count++] = -1;
        } else {
            /* To support source compatibility with glsl >= 1.3 which has
             * replaced
             * all of the texture sampler functions with one polymorphic
             * texture()
             * function we use the preprocessor to map the old names onto the
             * new
             * name...
             */
            strings[count] = "#define texture2D texture\n"
                             "#define texture3D texture\n"
                             "#define textureRect texture\n";
            lengths[count++] = -1;
        }

        strings[count] = vertex_boilerplate;
        lengths[count++] = strlen(vertex_boilerplate);
    } else if (shader_gl_type == GL_FRAGMENT_SHADER) {
        if (dev->glsl_version_to_use < 130) {
            strings[count] = "#define in varying\n"
                             "\n"
                             "#define cg_color_out gl_FragColor\n"
                             "#define cg_depth_out gl_FragDepth\n";
            lengths[count++] = -1;
        }

        strings[count] = fragment_boilerplate;
        lengths[count++] = strlen(fragment_boilerplate);

        if (dev->glsl_version_to_use >= 130) {
            /* FIXME: Support cg_depth_out. */
            /* To support source compatibility with glsl >= 1.3 which has
             * replaced
             * all of the texture sampler functions with one polymorphic
             * texture()
             * function we use the preprocessor to map the old names onto the
             * new
             * name...
             */
            strings[count] = "#define texture2D texture\n"
                             "#define texture3D texture\n"
                             "#define textureRect texture\n"
                             "\n"
                             "out vec4 cg_color_out;\n";
            //"out vec4 cg_depth_out\n";
            lengths[count++] = -1;
        }
    }

    memcpy(strings + count, strings_in, sizeof(char *) * count_in);
    if (lengths_in)
        memcpy(lengths + count, lengths_in, sizeof(GLint) * count_in);
    else {
        int i;

        for (i = 0; i < count_in; i++)
            lengths[count + i] = -1; /* null terminated */
    }
    count += count_in;

    if (C_UNLIKELY(CG_DEBUG_ENABLED(CG_DEBUG_SHOW_SOURCE))) {
        c_string_t *buf = c_string_new(NULL);
        int i;

        c_string_append_printf(buf,
                               "%s shader:\n",
                               shader_gl_type == GL_VERTEX_SHADER ? "vertex"
                               : "fragment");
        for (i = 0; i < count; i++)
            if (lengths[i] != -1)
                c_string_append_len(buf, strings[i], lengths[i]);
            else
                c_string_append(buf, strings[i]);

        c_message("%s", buf->str);

        c_string_free(buf, true);
    }

    GE(dev,
       glShaderSource(
           shader_gl_handle, count, (const char **)strings, lengths));

    c_free(version_string);
}