コード例 #1
0
ファイル: hcp_library.c プロジェクト: adamarvid/hcp
hcp_Int hcp_GetUint8(const hcp_tProtocol* pProtocol, const hcp_szStr Key, hcp_Uint8* pDest) {
	*pDest = 0;
	hcp_tString key;

	key.value = Key;
	key.length = hcp_szStrLen(Key);
	key.zeroTerm = HCP_TRUE;

	hcp_Boolean found = HCP_FALSE;
	hcp_Size_t index = hcp_FindFirst(&pProtocol->header, 0, &key, &found);

	if (found == HCP_FALSE) {
		return HCP_MISSINGCODECNODE;
	}

	hcp_tProtocolNode* node = (hcp_tProtocolNode*)hcp_ValueAt(&pProtocol->header, index);

	*pDest = (hcp_Uint8)hcp_Atio(&node->value);
	return HCP_NOERROR;
}
コード例 #2
0
ファイル: hcp_library.c プロジェクト: adamarvid/hcp
hcp_Int hcp_SetString(hcp_tParameterSet* pParameters, const hcp_tString* Name, const hcp_tString* Value) {
	hcp_Boolean found = HCP_FALSE;
	hcp_Size_t index = hcp_FindFirst(&pParameters->header, 0, (void*)Name, &found);
	hcp_tParameter* parameter = HCP_NULL;
	hcp_Int error = HCP_NOERROR;

	if (found == HCP_FALSE) {
		if ((error = hcp_PushEmpty(&pParameters->header, &index)) != HCP_NULL) {
			return error;
		}

		parameter = (hcp_tParameter*)hcp_ValueAt(&pParameters->header, index);
	}
	else {
		parameter = (hcp_tParameter*)hcp_ValueAt(&pParameters->header, index);
	}

	parameter->value.str = *Value;
	parameter->hasValue = HCP_TRUE;

	return HCP_NOERROR;
}
コード例 #3
0
ファイル: hcp.cpp プロジェクト: husqvarnagroup/hcp
bool hcp::Runtime::scanDir(const char* codecPath,const char** error) {
	uv_fs_t req;
	int numFiles = uv_fs_scandir(uv_default_loop(), &req, codecPath, UV_FS_SCANDIR, nullptr);

	if (numFiles < 0) {
		if (error) {
			*error = uv_strerror(numFiles);
		}

		return false;
	}

	for (int i = 0; i < numFiles; i++) {
		uv_dirent_t ent;
		hcp::tCodec codec;

		int r = uv_fs_scandir_next(&req, &ent);

		if (r == UV_EOF) {
			break;
		}

		hcp_Boolean found = HCP_FALSE;
		// skip codecs with duplicate name
		hcp_FindFirst(&_codecs.header, 0, (void*)ent.name, &found);

		if (found == HCP_TRUE) {
			continue;
		}

		if (hcp::Runtime::hasExtension(ent.name, ".DLL") ||
			hcp::Runtime::hasExtension(ent.name, ".SO") ||
        hcp::Runtime::hasExtension(ent.name, ".DYLIB")) {

			hcp_Size_t pathLen = hcp_szStrLen((hcp_szStr)codecPath);
			hcp_Size_t nameLen = hcp_szStrLen((hcp_szStr)ent.name);

			codec.path = (char*)hcp_Malloc(_state, pathLen + nameLen + 2);
			
			hcp_Memcpy(_state, codec.path, codecPath, pathLen);
			hcp_Memcpy(_state, codec.path + pathLen, "/", 1);
			hcp_Memcpy(_state, codec.path + pathLen + 1, ent.name, nameLen + 1);

			if (loadLibrary(codec.path, &codec, error)) {
				hcp_Size_t index;
				auto code = hcp_Push(&_codecs.header, &codec, &index);

				if (code != HCP_NOERROR) {
					// TODO: Logg load errors
					hcp_Free(_state, codec.path);
				}
			}
			else {
				// TODO: Logg load errors
				hcp_Free(_state, codec.path);
			}
		}
		else {
			continue;
		}
	}

	return true;
}