当前位置: 首页>>代码示例>>C++>>正文


C++ LOGE函数代码示例

本文整理汇总了C++中LOGE函数的典型用法代码示例。如果您正苦于以下问题:C++ LOGE函数的具体用法?C++ LOGE怎么用?C++ LOGE使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了LOGE函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getPortQueue

void SoftMP3::onQueueFilled(OMX_U32 portIndex) {
    if (mSignalledError || mOutputPortSettingsChange != NONE) {
        return;
    }

    List<BufferInfo *> &inQueue = getPortQueue(0);
    List<BufferInfo *> &outQueue = getPortQueue(1);

    while (!inQueue.empty() && !outQueue.empty()) {
        BufferInfo *inInfo = *inQueue.begin();
        OMX_BUFFERHEADERTYPE *inHeader = inInfo->mHeader;

        BufferInfo *outInfo = *outQueue.begin();
        OMX_BUFFERHEADERTYPE *outHeader = outInfo->mHeader;

        if (inHeader->nFlags & OMX_BUFFERFLAG_EOS) {
            inQueue.erase(inQueue.begin());
            inInfo->mOwnedByUs = false;
            notifyEmptyBufferDone(inHeader);

            outHeader->nFilledLen = 0;
            outHeader->nFlags = OMX_BUFFERFLAG_EOS;

            outQueue.erase(outQueue.begin());
            outInfo->mOwnedByUs = false;
            notifyFillBufferDone(outHeader);
            return;
        }

        if (inHeader->nOffset == 0) {
            mAnchorTimeUs = inHeader->nTimeStamp;
            mNumFramesOutput = 0;
        }

        mConfig->pInputBuffer =
            inHeader->pBuffer + inHeader->nOffset;

        mConfig->inputBufferCurrentLength = inHeader->nFilledLen;
        mConfig->inputBufferMaxLength = 0;
        mConfig->inputBufferUsedLength = 0;

        mConfig->outputFrameSize = kOutputBufferSize / sizeof(int16_t);

        mConfig->pOutputBuffer =
            reinterpret_cast<int16_t *>(outHeader->pBuffer);

        ERROR_CODE decoderErr;
        if ((decoderErr = pvmp3_framedecoder(mConfig, mDecoderBuf))
                != NO_DECODING_ERROR) {
            ALOGV("mp3 decoder returned error %d", decoderErr);

            if (decoderErr != NO_ENOUGH_MAIN_DATA_ERROR ||
                    mConfig->outputFrameSize == 0) {
                LOGE("mp3 decoder returned error %d", decoderErr);

                if (mConfig->outputFrameSize == 0) {
                    LOGE("Output frame size is 0");
                }

                notify(OMX_EventError, OMX_ErrorUndefined, decoderErr, NULL);
                mSignalledError = true;
                return;
            }

            // This is recoverable, just ignore the current frame and
            // play silence instead.
            memset(outHeader->pBuffer,
                   0,
                   mConfig->outputFrameSize * sizeof(int16_t));

            mConfig->inputBufferUsedLength = inHeader->nFilledLen;
        } else if (mConfig->samplingRate != mSamplingRate
                || mConfig->num_channels != mNumChannels) {
            mSamplingRate = mConfig->samplingRate;
            mNumChannels = mConfig->num_channels;

            notify(OMX_EventPortSettingsChanged, 1, 0, NULL);
            mOutputPortSettingsChange = AWAITING_DISABLED;
            return;
        }

        outHeader->nOffset = 0;
        outHeader->nFilledLen = mConfig->outputFrameSize * sizeof(int16_t);

        outHeader->nTimeStamp =
            mAnchorTimeUs
                + (mNumFramesOutput * 1000000ll) / mConfig->samplingRate;

        outHeader->nFlags = 0;

        CHECK_GE(inHeader->nFilledLen, mConfig->inputBufferUsedLength);

        inHeader->nOffset += mConfig->inputBufferUsedLength;
        inHeader->nFilledLen -= mConfig->inputBufferUsedLength;

        mNumFramesOutput += mConfig->outputFrameSize / mNumChannels;

        if (inHeader->nFilledLen == 0) {
            inInfo->mOwnedByUs = false;
            inQueue.erase(inQueue.begin());
//.........这里部分代码省略.........
开发者ID:drod2169,项目名称:platform_frameworks_base,代码行数:101,代码来源:SoftMP3.cpp

示例2: MOZ_ASSERT

nsresult
AppleMP3Reader::ReadMetadata(MediaInfo* aInfo,
                             MetadataTags** aTags)
{
  MOZ_ASSERT(OnTaskQueue());

  *aTags = nullptr;

  /*
   * Feed bytes into the parser until we have all the metadata we need to
   * set up the decoder. When the parser has enough data, it will
   * synchronously call back to |AudioMetadataCallback| below.
   */
  OSStatus rv;
  nsresult readrv;
  uint32_t offset = 0;
  do {
    char bytes[AUDIO_READ_BYTES];
    uint32_t numBytes = AUDIO_READ_BYTES;
    readrv = Read(&numBytes, bytes);

    rv = AudioFileStreamParseBytes(mAudioFileStream,
                                   numBytes,
                                   bytes,
                                   0 /* flags */);

    mMP3FrameParser.Parse(reinterpret_cast<uint8_t*>(bytes), numBytes, offset);

    offset += numBytes;

    // We have to do our decoder setup from the callback. When it's done it will
    // set mStreamReady.
  } while (!mStreamReady && !rv && NS_SUCCEEDED(readrv));

  if (rv) {
    LOGE("Error decoding audio stream metadata\n");
    return NS_ERROR_FAILURE;
  }

  if (!mAudioConverter) {
    LOGE("Failed to setup the AudioToolbox audio decoder\n");
    return NS_ERROR_FAILURE;
  }

  if (!mMP3FrameParser.IsMP3()) {
    LOGE("Frame parser failed to parse MP3 stream\n");
    return NS_ERROR_FAILURE;
  }

  if (mStreamReady) {
    aInfo->mAudio.mRate = mAudioSampleRate;
    aInfo->mAudio.mChannels = mAudioChannels;
  }

  // This special snowflake reader doesn't seem to set *aInfo = mInfo like all
  // the others. Yuck.
  mDuration = mMP3FrameParser.GetDuration();
  mInfo.mMetadataDuration.emplace(TimeUnit::FromMicroseconds(mDuration));
  aInfo->mMetadataDuration.emplace(TimeUnit::FromMicroseconds(mDuration));

  return NS_OK;
}
开发者ID:norihirou,项目名称:gecko-dev,代码行数:62,代码来源:AppleMP3Reader.cpp

示例3: TangoService_getConfig

bool TangoData::SetConfig(bool is_auto_recovery) {
  // Get the default TangoConfig.
  // We get the default config first and change the config
  // flag as needed.
  config_ = TangoService_getConfig(TANGO_CONFIG_DEFAULT);
  if (config_ == NULL) {
    LOGE("TangoService_getConfig(): Failed");
    return false;
  }

  // Turn on auto recovery for motion tracking.
  // Note that the auto-recovery is on by default.
  if (TangoConfig_setBool(config_, "config_enable_auto_recovery",
                          is_auto_recovery) != TANGO_SUCCESS) {
    LOGE("config_enable_auto_recovery(): Failed");
    return false;
  }

  // Get library version string from service.
  TangoConfig_getString(config_, "tango_service_library_version",
                        const_cast<char*>(lib_version_string.c_str()),
                        kVersionStringLength);

  // Setting up the start of service to ADF frame for the onPoseAvailable
  // callback,
  // it will check the localization status.
  TangoCoordinateFramePair pair;
  pair.base = TANGO_COORDINATE_FRAME_AREA_DESCRIPTION;
  pair.target = TANGO_COORDINATE_FRAME_START_OF_SERVICE;

  // Attach onPoseAvailable callback.
  // The callback will be called after the service is connected.
  if (TangoService_connectOnPoseAvailable(1, &pair, onPoseAvailable) !=
      TANGO_SUCCESS) {
    LOGE("TangoService_connectOnPoseAvailable(): Failed");
    return false;
  }

  // Attach onEventAvailable callback.
  // The callback will be called after the service is connected.
  if (TangoService_connectOnTangoEvent(onTangoEvent) != TANGO_SUCCESS) {
    LOGE("TangoService_connectOnTangoEvent(): Failed");
    return false;
  }

  // Load the most recent ADF.
  char* uuid_list;

  // uuid_list will contain a comma separated list of UUIDs.
  if (TangoService_getAreaDescriptionUUIDList(&uuid_list) != TANGO_SUCCESS) {
    LOGI("TangoService_getAreaDescriptionUUIDList");
  }

  // Parse the uuid_list to get the individual uuids.
  if (uuid_list != NULL && uuid_list[0] != '\0') {
    vector<string> adf_list;

    char* parsing_char;
    parsing_char = strtok(uuid_list, ",");
    while (parsing_char != NULL) {
      string s = string(parsing_char);
      adf_list.push_back(s);
      parsing_char = strtok(NULL, ",");
    }

    int list_size = adf_list.size();
    if (list_size == 0) {
      LOGE("List size is 0");
      return false;
    }
    cur_uuid = adf_list[list_size - 1];
    if (TangoConfig_setString(config_, "config_load_area_description_UUID",
                              adf_list[list_size - 1].c_str()) !=
        TANGO_SUCCESS) {
      LOGE("config_load_area_description_uuid Failed");
      return false;
    } else {
      LOGI("Load ADF: %s", adf_list[list_size - 1].c_str());
    }
  } else {
    LOGE("No area description file available, no file loaded.");
  }
  is_localized = false;
  return true;
}
开发者ID:AugmentedRealityCenter,项目名称:tango-examples-c,代码行数:85,代码来源:tango_data.cpp

示例4: ALIGN

int gpu_context_t::alloc_impl(int w, int h, int format, int usage,
        buffer_handle_t* pHandle, int* pStride, int bufferSize) {
    if (!pHandle || !pStride)
        return -EINVAL;

    size_t size, alignedw, alignedh;

    alignedw = ALIGN(w, 32);
    alignedh = ALIGN(h, 32);
    int colorFormat, bufferType;
    getGrallocInformationFromFormat(format, &colorFormat, &bufferType);

    switch (colorFormat) {
        case HAL_PIXEL_FORMAT_RGBA_8888:
        case HAL_PIXEL_FORMAT_RGBX_8888:
        case HAL_PIXEL_FORMAT_BGRA_8888:
            size = alignedw * alignedh * 4;
            break;
        case HAL_PIXEL_FORMAT_RGB_888:
            size = alignedw * alignedh * 3;
            break;
        case HAL_PIXEL_FORMAT_RGB_565:
        case HAL_PIXEL_FORMAT_RGBA_5551:
        case HAL_PIXEL_FORMAT_RGBA_4444:
            size = alignedw * alignedh * 2;
            break;

        // adreno formats
        case HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO:  // NV21
            size  = ALIGN(alignedw*alignedh, 4096);
            size += ALIGN(2 * ALIGN(w/2, 32) * ALIGN(h/2, 32), 4096);
            break;
        case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED:   // NV12
            // The chroma plane is subsampled,
            // but the pitch in bytes is unchanged
            // The GPU needs 4K alignment, but the video decoder needs 8K
            alignedw = ALIGN(w, 128);
            size  = ALIGN( alignedw * alignedh, 8192);
            size += ALIGN( alignedw * ALIGN(h/2, 32), 8192);
            break;
        case HAL_PIXEL_FORMAT_YCbCr_420_SP:
        case HAL_PIXEL_FORMAT_YCrCb_420_SP:
        case HAL_PIXEL_FORMAT_YV12:
            if ((w&1) || (h&1)) {
                LOGE("w or h is odd for the YUV format");
                return -EINVAL;
            }
            alignedw = ALIGN(w, 16);
            alignedh = h;
            size = alignedw*alignedh +
                    (ALIGN(alignedw/2, 16) * (alignedh/2))*2;
            size = ALIGN(size, 4096);
            break;

        default:
            LOGE("unrecognized pixel format: %d", format);
            return -EINVAL;
    }

    if ((ssize_t)size <= 0)
        return -EINVAL;

    size = (bufferSize >= size)? bufferSize : size;

    // All buffers marked as protected or for external
    // display need to go to overlay
    if ((usage & GRALLOC_USAGE_EXTERNAL_DISP) ||
        (usage & GRALLOC_USAGE_PROTECTED)) {
            bufferType = BUFFER_TYPE_VIDEO;
    }
    int err;
    if (usage & GRALLOC_USAGE_HW_FB) {
        err = gralloc_alloc_framebuffer(size, usage, pHandle);
    } else {
        err = gralloc_alloc_buffer(size, usage, pHandle, bufferType, format, alignedw, alignedh);
    }

    if (err < 0) {
        return err;
    }

    *pStride = alignedw;
    return 0;
}
开发者ID:AOKP,项目名称:hardware_msm7k,代码行数:84,代码来源:gpu.cpp

示例5: set_Parity

/**
 * @brief  : Configation UART           
 * @author : wchao
 * @date   :
 * @param  : fd,  nBits----, nParity----, nStop----
 * @return : int
 * @retval : 0----success; -1----fault
 * @Note   : 
 **/
int set_Parity(int fd,int nBits,int nParity,int nStop)
{
	struct termios newtio,oldtio;

	tcflush(fd, TCIOFLUSH);
	if  ( tcgetattr( fd,&oldtio)  !=  0)
	{
		LOGE("SetupSerial 1\n");
		return(FALSE);
	}

	bzero( &newtio, sizeof( newtio ) );
    newtio.c_cflag  |=  CLOCAL | CREAD;
    newtio.c_cflag &= ~CSIZE;
	
	switch (nBits) /*set databit*/
	{
	case 5:
        newtio.c_cflag |= CS5;
        break;
    case 6:
        newtio.c_cflag |= CS6;
        break;
    case 7:
        newtio.c_cflag |= CS7;
        break;
    case 8:
        newtio.c_cflag |= CS8;
        break;
    default:
        newtio.c_cflag |= CS8; //Unsupported data define CS8
        break;
	}
	
	switch (nParity)
	{
	case 'n':
	case 'N':
		newtio.c_cflag &= ~PARENB;			/* Clear parity enable */
		newtio.c_iflag &= ~INPCK;			/* Enable parity checking */
		break;
	case 'o':
	case 'O':
		newtio.c_cflag |= PARENB;
        newtio.c_cflag |= PARODD;			/* set party*/
        newtio.c_iflag |= (INPCK | ISTRIP);	/* Disnable parity checking */            
		break;
	case 'e':
	case 'E':
		newtio.c_iflag |= (INPCK | ISTRIP);	/* Disnable parity checking */
        newtio.c_cflag |= PARENB;			/* Enable parity */
        newtio.c_cflag &= ~PARODD;			/* Set party*/       
		break;
	case 'S':
	case 's':  /*as no parity*/
		newtio.c_cflag &= ~PARENB;
		newtio.c_cflag &= ~CSTOPB;
		break;
	default:
		newtio.c_cflag &= ~PARENB;
		newtio.c_iflag &= ~INPCK;
		break;
	}
	
	/* set stop*/   
	switch (nStop)
	{
	case 1:
		newtio.c_cflag &=  ~CSTOPB;
		break;
	case 2:
		newtio.c_cflag |=  CSTOPB;
		break;
	default:
		LOGE(stderr,"Unsupported stop bits\n");
		return (FALSE);
	}
	
	newtio.c_cc[VTIME] = 0; 
	newtio.c_cc[VMIN] = 0;

	tcflush(fd,TCIFLUSH); /* Update the options and do it NOW */
	if (tcsetattr(fd,TCSANOW,&newtio) != 0)
	{
		LOGE("SetupSerial 3\n");
		return (FALSE);
	}
	
#ifdef TEST_BUG
	LOGE("set done!\n");
#endif
//.........这里部分代码省略.........
开发者ID:DwaineGarden,项目名称:packages_apps_bonovoapps,代码行数:101,代码来源:serail.c

示例6: dvmInvokeMethod

/*
 * Invoke a method, using the specified arguments and return type, through
 * one of the reflection interfaces.  Could be a virtual or direct method
 * (including constructors).  Used for reflection.
 *
 * Deals with boxing/unboxing primitives and performs widening conversions.
 *
 * "invokeObj" will be null for a static method.
 *
 * If the invocation returns with an exception raised, we have to wrap it.
 */
Object* dvmInvokeMethod(Object* obj, const Method* method,
    ArrayObject* argList, ArrayObject* params, ClassObject* returnType,
    bool noAccessCheck)
{
    ClassObject* clazz;
    Object* retObj = NULL;
    Thread* self = dvmThreadSelf();
    s4* ins;
    int verifyCount, argListLength;
    JValue retval;

    /* verify arg count */
    if (argList != NULL)
        argListLength = argList->length;
    else
        argListLength = 0;
    if (argListLength != (int) params->length) {
        LOGI("invoke: expected %d args, received %d args\n",
            params->length, argListLength);
        dvmThrowException("Ljava/lang/IllegalArgumentException;",
            "wrong number of arguments");
        return NULL;
    }

    clazz = callPrep(self, method, obj, !noAccessCheck);
    if (clazz == NULL)
        return NULL;

    /* "ins" for new frame start at frame pointer plus locals */
    ins = ((s4*)self->curFrame) + (method->registersSize - method->insSize);
    verifyCount = 0;

    //LOGD("  FP is %p, INs live at >= %p\n", self->curFrame, ins);

    /* put "this" pointer into in0 if appropriate */
    if (!dvmIsStaticMethod(method)) {
        assert(obj != NULL);
        *ins++ = (s4) obj;
        verifyCount++;
    }

    /*
     * Copy the args onto the stack.  Primitive types are converted when
     * necessary, and object types are verified.
     */
    DataObject** args;
    ClassObject** types;
    int i;

    args = (DataObject**) argList->contents;
    types = (ClassObject**) params->contents;
    for (i = 0; i < argListLength; i++) {
        int width;

        width = dvmConvertArgument(*args++, *types++, ins);
        if (width < 0) {
            if (*(args-1) != NULL) {
                LOGV("invoke: type mismatch on arg %d ('%s' '%s')\n",
                    i, (*(args-1))->obj.clazz->descriptor,
                    (*(types-1))->descriptor);
            }
            dvmPopFrame(self);      // throw wants to pull PC out of stack
            dvmThrowException("Ljava/lang/IllegalArgumentException;",
                "argument type mismatch");
            goto bail_popped;
        }

        ins += width;
        verifyCount += width;
    }

    if (verifyCount != method->insSize) {
        LOGE("Got vfycount=%d insSize=%d for %s.%s\n", verifyCount,
            method->insSize, clazz->descriptor, method->name);
        assert(false);
        goto bail;
    }
    //dvmDumpThreadStack(dvmThreadSelf());

    if (dvmIsNativeMethod(method)) {
        /*
         * Because we leave no space for local variables, "curFrame" points
         * directly at the method arguments.
         */
        (*method->nativeFunc)(self->curFrame, &retval, method, self);
    } else {
        dvmInterpret(self, method, &retval);
    }

//.........这里部分代码省略.........
开发者ID:Katarzynasrom,项目名称:patch-hosting-for-android-x86-support,代码行数:101,代码来源:Stack.c

示例7: bson_iterator_from_buffer


//.........这里部分代码省略.........

		bson_type t = bson_iterator_type(&i);
		if (t == 0)
		{
			break;
		}
		key = bson_iterator_key(&i);

		if (key[0] != '\0')
		{
			sprintf(keybuf, "\"%s\":", key);
			key = &keybuf[0];
		}

		switch (t)
		{
		case BSON_DOUBLE:
			sprintf(buf, "%s%f", key, bson_iterator_double(&i));
			bufSize = strlen(buf);
			memcpy(&val[cursor], buf, bufSize);
			cursor += bufSize;
			break;
		case BSON_STRING:
			sprintf(buf, "%s\"%s\"", key, bson_iterator_string(&i));
			bufSize = strlen(buf);
			memcpy(&val[cursor], buf, bufSize);
			cursor += bufSize;
			break;
		case BSON_OID:
			bson_oid_to_string(bson_iterator_oid(&i), oidhex);
			sprintf(buf, "%s\"%s\"", key, oidhex);
			bufSize = strlen(buf);
			memcpy(&val[cursor], buf, bufSize);
			cursor += bufSize;
			break;
		case BSON_BOOL:
			sprintf(buf, "%s%s", key,
					bson_iterator_bool(&i) ? "true" : "false");
			bufSize = strlen(buf);
			memcpy(&val[cursor], buf, bufSize);
			cursor += bufSize;
			break;
		case BSON_NULL:
			sprintf(buf, "%snull", key);
			bufSize = strlen(buf);
			memcpy(&val[cursor], buf, bufSize);
			cursor += bufSize;
			break;
		case BSON_INT:
			sprintf(buf, "%s%d", key, bson_iterator_int(&i));
			bufSize = strlen(buf);
			memcpy(&val[cursor], buf, bufSize);
			cursor += bufSize;
			break;
		case BSON_OBJECT:
			sprintf(buf, "%s\0", key);
			memcpy(&val[cursor], buf, strlen(buf));
			cursor += strlen(buf);

			object = bson_to_json(val, bson_iterator_value(&i), depth + 1, true,
					bsonSize - cursor, jsonSize, cursor);

			break;
		case BSON_ARRAY:
			sprintf(buf, "%s", key);
			bufSize = strlen(buf);
			memcpy(&val[cursor], buf, bufSize);
			cursor += bufSize;

			object = bson_to_json(val, bson_iterator_value(&i), depth + 1,
					false, bsonSize - cursor, jsonSize, cursor);

			break;
		default:
			LOGE("can't print type");
			FORCE_LOG_INT("type: ", t);

			memcpy(&val[cursor], "}", 1);
			cursor += 1;
			jsonSize = cursor;
			return val;
		}
	}

	if (isObject)
	{
		memcpy(&val[cursor], "}", 1);
		cursor += 1;
		memcpy(&val[cursor], "\0", 1);

	}
	else
	{
		memcpy(&val[cursor], "]", 1);
		cursor += 1;
	}

	jsonSize = cursor;
	return val;
}
开发者ID:vamitrou,项目名称:JSONDroid,代码行数:101,代码来源:Namespace.cpp

示例8: receive_inotify_events

/**
 * @brief Handle inotify events
 *
 * Calls the callcbacks
 *
 * @param files nb max of logs destination directories (crashlog,
 * aplogs, bz... )
 *
 * @return 0 on success, -1 on error.
 */
int receive_inotify_events(int inotify_fd) {
    int len = 0, orig_len, idx, wd, missing_bytes;
    char orig_buffer[sizeof(struct inotify_event)+PATHMAX], *buffer, lastevent[sizeof(struct inotify_event)+PATHMAX];
    struct inotify_event *event;
    struct watch_entry *entry = NULL;

    len = read(inotify_fd, orig_buffer, sizeof(orig_buffer));
    if (len < 0) {
        LOGE("%s: Cannot read file_monitor_fd, error is %s\n", __FUNCTION__, strerror(errno));
        return -errno;
    }

    buffer = &orig_buffer[0];
    orig_len = len;
    event = (struct inotify_event *)buffer;

    /* Preinitialize lastevent (in case it was not used so it is not dumped) */
    ((struct inotify_event *)lastevent)->wd = 0;
    ((struct inotify_event *)lastevent)->mask = 0;
    ((struct inotify_event *)lastevent)->cookie = 0;
    ((struct inotify_event *)lastevent)->len = 0;

    while (1) {
        if (len == 0) {
            /* End of the events to read */
            return 0;
        }
        if ((unsigned int)len < sizeof(struct inotify_event)) {
            /* Not enough room for an empty event */
            LOGI("%s: incomplete inotify_event received (%d bytes), complete it\n", __FUNCTION__, len);
            /* copy the last bytes received */
            if( (unsigned int)len <= sizeof(lastevent) )
                memcpy(lastevent, buffer, len);
            else {
                LOGE("%s: Cannot copy buffer\n", __FUNCTION__);
                return -1;
            }
            /* read the missing bytes to get the full length */
            missing_bytes = (int)sizeof(struct inotify_event)-len;
            if(((int) len + missing_bytes) < ((int)sizeof(lastevent))) {
                if (read(inotify_fd, &lastevent[len], missing_bytes) != missing_bytes ){
                    LOGE("%s: Cannot complete the last inotify_event received (structure part) - %s\n", __FUNCTION__, strerror(errno));
                    return -1;
                }
            }
            else {
                LOGE("%s: Cannot read missing bytes, not enought space in lastevent\n", __FUNCTION__);
                return -1;
            }
            event = (struct inotify_event*)lastevent;
            /* now, reads the full last event, including its name field */
            if ( read(inotify_fd, &lastevent[sizeof(struct inotify_event)],
                event->len) != (int)event->len) {
                LOGE("%s: Cannot complete the last inotify_event received (name part) - %s\n",
                    __FUNCTION__, strerror(errno));
                return -1;
            }
            len = 0;
            /* now, the last event is complete, we can continue the parsing */
        } else if ( (unsigned int)len < sizeof(struct inotify_event) + event->len ) {
            int res, missing_bytes = (int)sizeof(struct inotify_event) + event->len - len;
            event = (struct inotify_event*)lastevent;
            /* The event was truncated */
            LOGI("%s: truncated inotify_event received (%d bytes missing), complete it\n", __FUNCTION__, missing_bytes);

            /* Robustness : check 'lastevent' array size before reading inotify fd*/
            if( (unsigned int)len > sizeof(lastevent) ) {
                LOGE("%s: not enough space on array lastevent.\n", __FUNCTION__);
                return -1;
            }
            /* copy the last bytes received */
            memcpy(lastevent, buffer, len);
            /* now, reads the full last event, including its name field */
            res = read(inotify_fd, &lastevent[len], missing_bytes);
            if ( res != missing_bytes ) {
                LOGE("%s: Cannot complete the last inotify_event received (name part2); received %d bytes, expected %d bytes - %s\n",
                    __FUNCTION__, res, missing_bytes, strerror(errno));
                return -1;
            }
            len = 0;
            /* now, the last event is complete, we can continue the parsing */
        } else {
            event = (struct inotify_event *)buffer;
            buffer += sizeof(struct inotify_event) + event->len;
            len -= sizeof(struct inotify_event) + event->len;
        }
        /* Handle the event read from the buffer*/
        /* First check the kind of the subject of this event (file or directory?) */
        if (!(event->mask & IN_ISDIR)) {
            /* event concerns a file into a watched directory */
//.........这里部分代码省略.........
开发者ID:yutokt,项目名称:android_vendor_intel,代码行数:101,代码来源:inotify_handler.c

示例9: orxAndroid_PumpEvents

extern "C" void orxAndroid_PumpEvents()
{
  int ident;
  int events;

  while ((ident=ALooper_pollAll(isInteractible() || sstAndroid.bDestroyRequested == orxTRUE ? 0 : -1, NULL, &events, NULL)) >= 0)
  {
    if(ident == LOOPER_ID_MAIN)
    {
      int8_t cmd = app_read_cmd();

      if(cmd == APP_CMD_PAUSE) {
        LOGI("APP_CMD_PAUSE");
        sstAndroid.bPaused = orxTRUE;
        orxEvent_SendShort(orxEVENT_TYPE_SYSTEM, orxSYSTEM_EVENT_BACKGROUND);
      }
      if(cmd == APP_CMD_RESUME) {
        LOGI("APP_CMD_RESUME");
        sstAndroid.bPaused = orxFALSE;
        orxEvent_SendShort(orxEVENT_TYPE_SYSTEM, orxSYSTEM_EVENT_FOREGROUND);
      }
      if(cmd == APP_CMD_SURFACE_DESTROYED) {
        LOGI("APP_CMD_SURFACE_DESTROYED");
        pthread_cond_broadcast(&sstAndroid.cond);

        sstAndroid.fSurfaceScale = orxFLOAT_0;
        orxEVENT_SEND(orxANDROID_EVENT_TYPE_SURFACE, orxANDROID_EVENT_SURFACE_DESTROYED, orxNULL, orxNULL, orxNULL);

        pthread_mutex_lock(&sstAndroid.mutex);
        if(sstAndroid.window != NULL)
        {
          ANativeWindow_release(sstAndroid.window);
          sstAndroid.window = NULL;
        }
        pthread_cond_broadcast(&sstAndroid.cond);
        pthread_mutex_unlock(&sstAndroid.mutex);
      }
      if(cmd == APP_CMD_SURFACE_CHANGED) {
        LOGI("APP_CMD_SURFACE_CHANGED");
        orxANDROID_SURFACE_CHANGED_EVENT stSurfaceChangedEvent;
        stSurfaceChangedEvent.u32Width = sstAndroid.u32SurfaceWidth;
        stSurfaceChangedEvent.u32Height = sstAndroid.u32SurfaceHeight;
        sstAndroid.fSurfaceScale = orxFLOAT_0;
        orxEVENT_SEND(orxANDROID_EVENT_TYPE_SURFACE, orxANDROID_EVENT_SURFACE_CHANGED, orxNULL, orxNULL, &stSurfaceChangedEvent);
      }
      if(cmd == APP_CMD_SURFACE_CREATED) {
        LOGI("APP_CMD_SURFACE_CREATED");
        pthread_mutex_lock(&sstAndroid.mutex);
        sstAndroid.window = sstAndroid.pendingWindow;
        pthread_cond_broadcast(&sstAndroid.cond);
        pthread_mutex_unlock(&sstAndroid.mutex);

        orxEVENT_SEND(orxANDROID_EVENT_TYPE_SURFACE, orxANDROID_EVENT_SURFACE_CREATED, orxNULL, orxNULL, orxNULL);
      }
      if(cmd == APP_CMD_QUIT) {
        LOGI("APP_CMD_QUIT");
        sstAndroid.bDestroyRequested = orxTRUE;
        orxEvent_SendShort(orxEVENT_TYPE_SYSTEM, orxSYSTEM_EVENT_CLOSE);
      }
      if(cmd == APP_CMD_FOCUS_GAINED) {
        LOGI("APP_CMD_FOCUS_GAINED");
        sstAndroid.bHasFocus = orxTRUE;
        orxEvent_SendShort(orxEVENT_TYPE_SYSTEM, orxSYSTEM_EVENT_FOCUS_GAINED);
      }
      if(cmd == APP_CMD_FOCUS_LOST) {
        LOGI("APP_CMD_FOCUS_LOST");
        sstAndroid.bHasFocus = orxFALSE;
        orxEvent_SendShort(orxEVENT_TYPE_SYSTEM, orxSYSTEM_EVENT_FOCUS_LOST);
      }
    }

    if(ident == LOOPER_ID_SENSOR)
    {
      orxEvent_SendShort(orxANDROID_EVENT_TYPE_ACCELERATE, 0);
    }

    if(ident == LOOPER_ID_KEY_EVENT)
    {
      orxANDROID_KEY_EVENT stKeyEvent;

      if (read(sstAndroid.pipeKeyEvent[0], &stKeyEvent, sizeof(stKeyEvent)) == sizeof(stKeyEvent))
      {
        orxEVENT_SEND(orxANDROID_EVENT_TYPE_KEYBOARD, 0, orxNULL, orxNULL, &stKeyEvent);
      } else {
        LOGE("No data on command pipe!");
      }
    }

    if(ident == LOOPER_ID_TOUCH_EVENT)
    {
      orxANDROID_TOUCH_EVENT stTouchEvent;

      if (read(sstAndroid.pipeTouchEvent[0], &stTouchEvent, sizeof(stTouchEvent)) == sizeof(stTouchEvent))
      {
        orxSYSTEM_EVENT_PAYLOAD stPayload;

        if(sstAndroid.fSurfaceScale == orxFLOAT_0)
        {
          orxConfig_PushSection(KZ_CONFIG_ANDROID);
          sstAndroid.fSurfaceScale = orxConfig_GetFloat(KZ_CONFIG_SURFACE_SCALE);
//.........这里部分代码省略.........
开发者ID:orx,项目名称:orx,代码行数:101,代码来源:orxAndroidSupport.cpp

示例10: datacopier_readable

static void datacopier_readable(libxl__egc *egc, libxl__ev_fd *ev,
                                int fd, short events, short revents) {
    libxl__datacopier_state *dc = CONTAINER_OF(ev, *dc, toread);
    STATE_AO_GC(dc->ao);

    if (datacopier_pollhup_handled(egc, dc, revents, 0))
        return;

    if (revents & ~POLLIN) {
        LOG(ERROR, "unexpected poll event 0x%x (should be POLLIN)"
            " on %s during copy of %s", revents, dc->readwhat, dc->copywhat);
        datacopier_callback(egc, dc, -1, 0);
        return;
    }
    assert(revents & POLLIN);
    for (;;) {
        while (dc->used >= dc->maxsz) {
            libxl__datacopier_buf *rm = LIBXL_TAILQ_FIRST(&dc->bufs);
            dc->used -= rm->used;
            assert(dc->used >= 0);
            LIBXL_TAILQ_REMOVE(&dc->bufs, rm, entry);
            free(rm);
        }

        libxl__datacopier_buf *buf =
            LIBXL_TAILQ_LAST(&dc->bufs, libxl__datacopier_bufs);
        if (!buf || buf->used >= sizeof(buf->buf)) {
            buf = malloc(sizeof(*buf));
            if (!buf) libxl__alloc_failed(CTX, __func__, 1, sizeof(*buf));
            buf->used = 0;
            LIBXL_TAILQ_INSERT_TAIL(&dc->bufs, buf, entry);
        }
        int r = read(ev->fd,
                     buf->buf + buf->used,
                     sizeof(buf->buf) - buf->used);
        if (r < 0) {
            if (errno == EINTR) continue;
            if (errno == EWOULDBLOCK) break;
            LOGE(ERROR, "error reading %s during copy of %s",
                 dc->readwhat, dc->copywhat);
            datacopier_callback(egc, dc, 0, errno);
            return;
        }
        if (r == 0) {
            libxl__ev_fd_deregister(gc, &dc->toread);
            break;
        }
        if (dc->log) {
            int wrote = fwrite(buf->buf + buf->used, 1, r, dc->log);
            if (wrote != r) {
                assert(ferror(dc->log));
                assert(errno);
                LOGE(ERROR, "error logging %s", dc->copywhat);
                datacopier_callback(egc, dc, 0, errno);
                return;
            }
        }
        buf->used += r;
        dc->used += r;
        assert(buf->used <= sizeof(buf->buf));
    }
    datacopier_check_state(egc, dc);
}
开发者ID:CrazyXen,项目名称:XEN_CODE,代码行数:63,代码来源:libxl_aoutils.c

示例11: libxl__openptys

int libxl__openptys(libxl__openpty_state *op,
                    struct termios *termp,
                    struct winsize *winp) {
    /*
     * This is completely crazy.  openpty calls grantpt which the spec
     * says may fork, and may not be called with a SIGCHLD handler.
     * Now our application may have a SIGCHLD handler so that's bad.
     * We could perhaps block it but we'd need to block it on all
     * threads.  This is just Too Hard.
     *
     * So instead, we run openpty in a child process.  That child
     * process then of course has only our own thread and our own
     * signal handlers.  We pass the fds back.
     *
     * Since our only current caller actually wants two ptys, we
     * support calling openpty multiple times for a single fork.
     */
    STATE_AO_GC(op->ao);
    int count = op->count;
    int r, i, rc, sockets[2], ptyfds[count][2];
    libxl__carefd *for_child = 0;
    pid_t pid = -1;

    for (i=0; i<count; i++) {
        ptyfds[i][0] = ptyfds[i][1] = -1;
        libxl__openpty_result *res = &op->results[i];
        assert(!res->master);
        assert(!res->slave);
    }
    sockets[0] = sockets[1] = -1; /* 0 is for us, 1 for our child */

    libxl__carefd_begin();
    r = socketpair(AF_UNIX, SOCK_STREAM, 0, sockets);
    if (r) { sockets[0] = sockets[1] = -1; }
    for_child = libxl__carefd_opened(CTX, sockets[1]);
    if (r) { LOGE(ERROR,"socketpair failed"); rc = ERROR_FAIL; goto out; }

    pid = libxl__ev_child_fork(gc, &op->child, openpty_exited);
    if (pid == -1) {
        rc = ERROR_FAIL;
        goto out;
    }

    if (!pid) {
        /* child */
        close(sockets[0]);
        signal(SIGCHLD, SIG_DFL);

        for (i=0; i<count; i++) {
            r = openpty(&ptyfds[i][0], &ptyfds[i][1], NULL, termp, winp);
            if (r) { LOGE(ERROR,"openpty failed"); _exit(-1); }
        }
        rc = libxl__sendmsg_fds(gc, sockets[1], "",1,
                                2*count, &ptyfds[0][0], "ptys");
        if (rc) { LOGE(ERROR,"sendmsg to parent failed"); _exit(-1); }
        _exit(0);
    }

    libxl__carefd_close(for_child);
    for_child = 0;

    /* this should be fast so do it synchronously */

    libxl__carefd_begin();
    char buf[1];
    rc = libxl__recvmsg_fds(gc, sockets[0], buf,1,
                            2*count, &ptyfds[0][0], "ptys");
    if (!rc) {
        for (i=0; i<count; i++) {
            libxl__openpty_result *res = &op->results[i];
            res->master = libxl__carefd_record(CTX, ptyfds[i][0]);
            res->slave =  libxl__carefd_record(CTX, ptyfds[i][1]);
        }
    }
    /* now the pty fds are in the carefds, if they were ever open */
    libxl__carefd_unlock();
    if (rc)
        goto out;

    rc = 0;

 out:
    if (sockets[0] >= 0) close(sockets[0]);
    libxl__carefd_close(for_child);
    if (libxl__ev_child_inuse(&op->child)) {
        op->rc = rc;
        /* we will get a callback when the child dies */
        return 0;
    }

    assert(rc);
    openpty_cleanup(op);
    return rc;
}
开发者ID:CrazyXen,项目名称:XEN_CODE,代码行数:94,代码来源:libxl_aoutils.c

示例12: memset

bool MtkFormat::createImage(std::vector<unsigned char> *dataOut)
{
    BootImageHeader hdr;
    std::vector<unsigned char> data;

    memset(&hdr, 0, sizeof(BootImageHeader));

    bool hasKernelHdr = !mI10e->mtkKernelHdr.empty();
    bool hasRamdiskHdr = !mI10e->mtkRamdiskHdr.empty();

    // Check header sizes
    if (hasKernelHdr && mI10e->mtkKernelHdr.size() != sizeof(MtkHeader)) {
        LOGE("Expected %" PRIzu " byte kernel MTK header, but have %" PRIzu " bytes",
             sizeof(MtkHeader), mI10e->mtkKernelHdr.size());
        return false;
    }
    if (hasRamdiskHdr && mI10e->mtkRamdiskHdr.size() != sizeof(MtkHeader)) {
        LOGE("Expected %" PRIzu " byte ramdisk MTK header, but have %" PRIzu " bytes",
             sizeof(MtkHeader), mI10e->mtkRamdiskHdr.size());
        return false;
    }

    std::size_t kernelSize =
            mI10e->kernelImage.size() + mI10e->mtkKernelHdr.size();
    std::size_t ramdiskSize =
            mI10e->ramdiskImage.size() + mI10e->mtkRamdiskHdr.size();

    MtkHeader mtkKernelHdr;
    MtkHeader mtkRamdiskHdr;
    if (hasKernelHdr) {
        std::memcpy(&mtkKernelHdr, mI10e->mtkKernelHdr.data(), sizeof(MtkHeader));
        mtkKernelHdr.size = mI10e->kernelImage.size();
    }
    if (hasRamdiskHdr) {
        std::memcpy(&mtkRamdiskHdr, mI10e->mtkRamdiskHdr.data(), sizeof(MtkHeader));
        mtkRamdiskHdr.size = mI10e->ramdiskImage.size();
    }

    // Set header metadata fields
    memcpy(hdr.magic, BOOT_MAGIC, BOOT_MAGIC_SIZE);
    hdr.kernel_size = kernelSize;
    hdr.kernel_addr = mI10e->kernelAddr;
    hdr.ramdisk_size = ramdiskSize;
    hdr.ramdisk_addr = mI10e->ramdiskAddr;
    hdr.second_size = mI10e->hdrSecondSize;
    hdr.second_addr = mI10e->secondAddr;
    hdr.tags_addr = mI10e->tagsAddr;
    hdr.page_size = mI10e->pageSize;
    hdr.dt_size = mI10e->hdrDtSize;
    hdr.unused = mI10e->hdrUnused;
    // -1 for null byte
    std::strcpy(reinterpret_cast<char *>(hdr.name),
                mI10e->boardName.substr(0, BOOT_NAME_SIZE - 1).c_str());
    std::strcpy(reinterpret_cast<char *>(hdr.cmdline),
                mI10e->cmdline.substr(0, BOOT_ARGS_SIZE - 1).c_str());

    // Update SHA1
    updateSha1Hash(&hdr, mI10e,
                   hasKernelHdr ? &mtkKernelHdr : nullptr,
                   hasRamdiskHdr ? &mtkRamdiskHdr : nullptr,
                   kernelSize, ramdiskSize);

    switch (mI10e->pageSize) {
    case 2048:
    case 4096:
    case 8192:
    case 16384:
    case 32768:
    case 65536:
    case 131072:
        break;
    default:
        LOGE("Invalid page size: %u", mI10e->pageSize);
        return false;
    }

    // Header
    unsigned char *hdrBegin = reinterpret_cast<unsigned char *>(&hdr);
    data.insert(data.end(), hdrBegin, hdrBegin + sizeof(BootImageHeader));

    // Padding
    uint32_t paddingSize = skipPadding(sizeof(BootImageHeader), hdr.page_size);
    data.insert(data.end(), paddingSize, 0);

    // Kernel image
    if (hasKernelHdr) {
        data.insert(data.end(),
                    reinterpret_cast<const unsigned char *>(&mtkKernelHdr),
                    reinterpret_cast<const unsigned char *>(&mtkKernelHdr) + sizeof(MtkHeader));
    }
    data.insert(data.end(),
                mI10e->kernelImage.begin(),
                mI10e->kernelImage.end());

    // More padding
    paddingSize = skipPadding(kernelSize, hdr.page_size);
    data.insert(data.end(), paddingSize, 0);

    // Ramdisk image
    if (hasRamdiskHdr) {
//.........这里部分代码省略.........
开发者ID:DTox187x,项目名称:DualBootPatcher,代码行数:101,代码来源:mtkformat.cpp

示例13: dumpMtkHeader

bool MtkFormat::loadImage(const unsigned char *data, std::size_t size)
{
    // We can load the image as an Android boot image
    if (!mbp::AndroidFormat::loadImage(data, size)) {
        return false;
    }

    // Check if the kernel has an mtk header
    if (mI10e->hdrKernelSize >= sizeof(MtkHeader)) {
        auto mtkHdr = reinterpret_cast<const MtkHeader *>(mI10e->kernelImage.data());
        // Check magic
        if (std::memcmp(mtkHdr->magic, MTK_MAGIC, MTK_MAGIC_SIZE) == 0) {
            dumpMtkHeader(mtkHdr);

            std::size_t expected = sizeof(MtkHeader) + mtkHdr->size;
            std::size_t actual = mI10e->kernelImage.size();

            // Check size
            if (actual < expected) {
                LOGE("Expected %" PRIzu " byte kernel image, but have %" PRIzu " bytes",
                     expected, actual);
                return false;
            } else if (actual != expected) {
                LOGW("Expected %" PRIzu " byte kernel image, but have %" PRIzu " bytes",
                     expected, actual);
                LOGW("Repacked boot image will not be byte-for-byte identical to original");
            }

            // Move header to mI10e->mtkKernelHdr
            mI10e->mtkKernelHdr.assign(
                    mI10e->kernelImage.begin(),
                    mI10e->kernelImage.begin() + sizeof(MtkHeader));
            std::vector<unsigned char>(
                    mI10e->kernelImage.begin() + sizeof(MtkHeader),
                    mI10e->kernelImage.end())
                    .swap(mI10e->kernelImage);

            auto newMtkHdr = reinterpret_cast<MtkHeader *>(mI10e->mtkKernelHdr.data());
            newMtkHdr->size = 0;
        }
    }

    // Check if the ramdisk has an mtk header
    if (mI10e->hdrRamdiskSize >= sizeof(MtkHeader)) {
        auto mtkHdr = reinterpret_cast<const MtkHeader *>(mI10e->ramdiskImage.data());
        // Check magic
        if (std::memcmp(mtkHdr->magic, MTK_MAGIC, MTK_MAGIC_SIZE) == 0) {
            dumpMtkHeader(mtkHdr);

            std::size_t expected = sizeof(MtkHeader) + mtkHdr->size;
            std::size_t actual = mI10e->ramdiskImage.size();

            // Check size
            if (actual != expected) {
                LOGE("Expected %" PRIzu " byte ramdisk image, but have %" PRIzu " bytes",
                     expected, actual);
                return false;
            }

            // Move header to mI10e->mtkRamdiskHdr
            mI10e->mtkRamdiskHdr.assign(
                    mI10e->ramdiskImage.begin(),
                    mI10e->ramdiskImage.begin() + sizeof(MtkHeader));
            std::vector<unsigned char>(
                    mI10e->ramdiskImage.begin() + sizeof(MtkHeader),
                    mI10e->ramdiskImage.end())
                    .swap(mI10e->ramdiskImage);

            auto newMtkHdr = reinterpret_cast<MtkHeader *>(mI10e->mtkRamdiskHdr.data());
            newMtkHdr->size = 0;
        }
    }

    return true;
}
开发者ID:DTox187x,项目名称:DualBootPatcher,代码行数:75,代码来源:mtkformat.cpp

示例14: dvmCallMethodV

/*
 * Issue a method call with a variable number of arguments.  We process
 * the contents of "args" by scanning the method signature.
 *
 * Pass in NULL for "obj" on calls to static methods.
 *
 * We don't need to take the class as an argument because, in Dalvik,
 * we don't need to worry about static synchronized methods.
 */
void dvmCallMethodV(Thread* self, const Method* method, Object* obj,
    JValue* pResult, va_list args)
{
    const char* desc = &(method->shorty[1]); // [0] is the return type.
    int verifyCount = 0;
    ClassObject* clazz;
    u4* ins;

    clazz = callPrep(self, method, obj, false);
    if (clazz == NULL)
        return;

    /* "ins" for new frame start at frame pointer plus locals */
    ins = ((u4*)self->curFrame) + (method->registersSize - method->insSize);

    //LOGD("  FP is %p, INs live at >= %p\n", self->curFrame, ins);

    /* put "this" pointer into in0 if appropriate */
    if (!dvmIsStaticMethod(method)) {
#ifdef WITH_EXTRA_OBJECT_VALIDATION
        assert(obj != NULL && dvmIsValidObject(obj));
#endif
        *ins++ = (u4) obj;
        verifyCount++;
    }

    while (*desc != '\0') {
        switch (*(desc++)) {
            case 'D': case 'J': {
                u8 val = va_arg(args, u8);
                memcpy(ins, &val, 8);       // EABI prevents direct store
                ins += 2;
                verifyCount += 2;
                break;
            }
            case 'F': {
                /* floats were normalized to doubles; convert back */
                float f = (float) va_arg(args, double);
                *ins++ = dvmFloatToU4(f);
                verifyCount++;
                break;
            }
#ifdef WITH_EXTRA_OBJECT_VALIDATION
            case 'L': {     /* 'shorty' descr uses L for all refs, incl array */
                Object* argObj = (Object*) va_arg(args, u4);
                assert(obj == NULL || dvmIsValidObject(obj));
                *ins++ = (u4) argObj;
                verifyCount++;
                break;
            }
#endif
            default: {
                *ins++ = va_arg(args, u4);
                verifyCount++;
                break;
            }
        }
    }

#ifndef NDEBUG
    if (verifyCount != method->insSize) {
        LOGE("Got vfycount=%d insSize=%d for %s.%s\n", verifyCount,
            method->insSize, clazz->descriptor, method->name);
        assert(false);
        goto bail;
    }
#endif

    //dvmDumpThreadStack(dvmThreadSelf());

    if (dvmIsNativeMethod(method)) {
        /*
         * Because we leave no space for local variables, "curFrame" points
         * directly at the method arguments.
         */
        (*method->nativeFunc)(self->curFrame, pResult, method, self);
    } else {
        dvmInterpret(self, method, pResult);
    }

bail:
    dvmPopFrame(self);
}
开发者ID:Katarzynasrom,项目名称:patch-hosting-for-android-x86-support,代码行数:92,代码来源:Stack.c

示例15: memset


//.........这里部分代码省略.........
	}
    tcp1 = socket(AF_INET, SOCK_STREAM, 0);
	if (tcp1 == -1){
		goto clean;
	}
    if (-1 == connect(tcp1, (sockaddr*)&name, namelen)){
		goto clean;
	}
#ifdef ANDROID
    tcp2 = accept(tcp, (sockaddr*)&name, (socklen_t *)&namelen);
#else
    tcp2 = accept(tcp, (sockaddr*)&name, &namelen);
#endif
	if (tcp2 == -1){
		goto clean;
	}
#ifdef WIN32
    if (closesocket(tcp) == -1){
#else
    if (close(tcp) == -1){
#endif
        goto clean;
	}
	m_Write_Sign = tcp1;
	m_Read_Sign = tcp2;
#ifdef WIN32
    {
        u_long iMode = 1;
        ioctlsocket(m_Read_Sign, FIONBIO, (u_long FAR*) &iMode);
    }
#else
    #include<fcntl.h>
    fcntl(m_Read_Sign,F_SETFL, O_NONBLOCK);
#endif
    return true;

clean:
	if (tcp != -1){
#ifdef WIN32
        closesocket(tcp);
#else
        close(tcp);
#endif
    }
	if (tcp2 != -1){
#ifdef WIN32
        closesocket(tcp2);
#else
        close(tcp2);
#endif
    }
	if (tcp1 != -1){
#ifdef WIN32
        closesocket(tcp1);
#else
        close(tcp1);
#endif
    }
	return false;
}

void* StartSocketThread(void* p) {
	SocketsToSDL * pThis = (SocketsToSDL *)p;
	pThis->RunThread();
	return 0;
}

bool SocketsToSDL::ConnectTo(std::vector<IChannel *> Channels, INetworkStatus * pNetwork)
{
    m_pNetwork = pNetwork;
	if (!CreateSignal())
		return false;

    int iNum = Channels.size();
    for (int i = 0; i < iNum; i++)
	{
        LOGE("-------");
        SOCK_HANDLE * pHandle = getNewSocketHandle(Channels[i], m_sHost, m_iPort);

        if(pHandle != NULL)
        {
            m_SocketHandles.push_back(pHandle);
            Channels[i]->setSocketManager(this, pHandle);
        }
        else
        {
            goto FAILED;
        }
	}

    m_bTerminate = false;
	if (0 != pthread_create(&m_SendThread, 0, &StartSocketThread, this))
		goto FAILED;

    return true;

FAILED:
    CloseSockets();
    return false;
}
开发者ID:smartdevice475,项目名称:hmi_sdl_android,代码行数:101,代码来源:SocketsToSDL.cpp


注:本文中的LOGE函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。