示例#1
0
void NVEventQueue::Init()
{
  m_nextInsertIndex = 0;
  m_headIndex = 0;
  pthread_mutex_init(&m_accessLock, NULL);
  syncInit(&m_consumerSync);
  syncInit(&m_blockerSync);

  m_blocker = NULL;
  m_blockerState = NO_BLOCKER;
  m_blockerReturnVal = false;
}
示例#2
0
static void NVEventInit(JNIEnv* env, jobject thiz)
{
    if (!s_globalThiz)
    {
        s_globalThiz = env->NewGlobalRef(thiz);
        if (!s_globalThiz)
        {
            __android_log_print(ANDROID_LOG_DEBUG, MODULE,  "Error: Thiz NewGlobalRef failed!");
        }

        __android_log_print(ANDROID_LOG_DEBUG, MODULE,  "Thiz NewGlobalRef: 0x%p", s_globalThiz);
    }

    __android_log_print(ANDROID_LOG_DEBUG, MODULE,  "initMap");
	initMap(env, thiz);

	__android_log_print(ANDROID_LOG_DEBUG, MODULE,  "file methods");
	
    jclass activity_class = env->FindClass("com/nvidia/devtech/NvEventQueueActivity");
    s_loadFile = env->GetMethodID(activity_class, "loadFile", "(Ljava/lang/String;)Lcom/nvidia/devtech/NvEventQueueActivity$RawData;");
    jclass RawData_class = env->FindClass("com/nvidia/devtech/NvEventQueueActivity$RawData");
    s_lengthId    = env->GetFieldID(RawData_class, "length", "I");
    s_dataId      = env->GetFieldID(RawData_class, "data", "[B");

	__android_log_print(ANDROID_LOG_DEBUG, MODULE,  "texture methods");
	
    s_loadTexture = env->GetMethodID(activity_class, "loadTexture", "(Ljava/lang/String;)Lcom/nvidia/devtech/NvEventQueueActivity$RawTexture;");
    jclass RawTexture_class = env->FindClass("com/nvidia/devtech/NvEventQueueActivity$RawTexture");
    s_widthId    = env->GetFieldID(RawTexture_class, "width", "I");
    s_heightId   = env->GetFieldID(RawTexture_class, "height", "I");
    s_texDataId     = env->GetFieldID(RawTexture_class, "data", "[B");

	s_getOri = env->GetMethodID(activity_class, "getOrientation", "()I");

	s_eventQueue.m_nextInsertIndex = 0;
	s_eventQueue.m_headIndex = 0;
	pthread_mutex_init(&(s_eventQueue.m_mutex), NULL);
	syncInit(&s_eventQueue.m_nativeSync);
	syncInit(&s_eventQueue.m_javaSync);
	s_eventQueue.m_processingPause = false;
	s_eventQueue.m_waitEventTypeCount = 0;
	s_eventQueue.m_waitEventTypes = NULL;
	__android_log_print(ANDROID_LOG_DEBUG, MODULE,  "Leave NVEventInit");
}
示例#3
0
int handleClient(int cfd, struct sockaddr *claddr, socklen_t *addrlen) {
    long long tbytes = 0; // total number of transfered bytes
    char addrstr[IS_ADDR_STR_LEN];

    errMsg(LOG_INFO, "Connection from %s", inetAddressStr(claddr, *addrlen,
            addrstr, IS_ADDR_STR_LEN));

    // sync-init, return value is number of files
    int32_t nfiles;
    nfiles = syncInit(cfd, &tbytes);
    if (nfiles == -1)
        return -1;
    
    errMsg(LOG_INFO, "Number of files to synchronize: %d", nfiles);
    // outer loop: files, inner loop: chunks
    for (int i = 0; i < nfiles; i++) {
        FileChunk *chunk;
        int fd = -1;

        // we are guaranteed to get at least one chunk for each file
        chunk = (FileChunk *) recvMessage(cfd, FileChunkType, &tbytes);
        if (chunk == NULL) {
            errMsg(LOG_ERR, "Could not read message from client.");
            return -1;
        }

        for (;;) {
            for (int k = 0; k < chunk->n_ops; k++) {
                // TODO
                // in case of a failure inform client to do an rsync based sync
                handleGenericOperation(&fd, chunk->relative_path, chunk->ops[k]);
            }

            if (chunk->last_chunk == 1) {
                file_chunk__free_unpacked(chunk, NULL);
                break;
            } else {
                file_chunk__free_unpacked(chunk, NULL);
                chunk = (FileChunk *) recvMessage(cfd, FileChunkType, &tbytes);
                if (chunk == NULL) {
                    errMsg(LOG_ERR, "Could not read message from client.");
                    return -1;
                }
            }
        }

        if (fd != -1) {
            if (close(fd) == -1)
                errMsg(LOG_WARNING, "Could not close file.");
        }

    }

    errMsg(LOG_INFO, "Received bytes: %lld", tbytes);

    // transfer was successful, we can delete snapshot (created in syncInit())
    if (deleteSnapshot(config.snapshot) == -1) {
        errMsg(LOG_ERR, "Could not delete snapshot %s", config.snapshot);
        close(cfd);
        return -1;
    }

    // rename resource.syncid to resource.syncid.last
    char lastsyncidpath[PATH_MAX];
    char syncidpath[PATH_MAX];
    snprintf(lastsyncidpath, PATH_MAX, "%s/%s.syncid.last", config.logdir,
            config.resource);
    snprintf(syncidpath, PATH_MAX, "%s/%s.syncid", config.logdir,
            config.resource);

    if (rename(syncidpath, lastsyncidpath) == -1) {
        errnoMsg(LOG_CRIT, "Could not rename sync-id file to sync-id.last.");
        close(cfd);
        return -1;
    }

    // and finally send confirmation to client
    SyncFinish conf = SYNC_FINISH__INIT;
    conf.has_transferred_bytes = 1;
    conf.transferred_bytes = (uint64_t) tbytes;
    if (sendMessage(cfd, SyncFinishType, &conf) != 0) {
        close(cfd);
        return -1;
    }

    if (close(cfd) == -1)
        errMsg(LOG_WARNING, "Could not close socket.");
    
    return 0;
}