Пример #1
0
static struct deviceRecord *buildDeviceRecord(io_object_t hidDevice)
{
	struct deviceRecord		*deviceRec;
	kern_return_t				result;
	CFMutableDictionaryRef	hidProperties = 0;

	deviceRec = (struct deviceRecord *) malloc(sizeof (struct deviceRecord));

	if (deviceRec)			// get dictionary for HID properties
	{
		result = IORegistryEntryCreateCFProperties(hidDevice, &hidProperties, kCFAllocatorDefault, kNilOptions);

		bzero(deviceRec, sizeof(struct deviceRecord));

		if ((!result) && (hidProperties))
		{
						// create device interface
			result = openDeviceInterface(hidDevice, deviceRec);

			if (verbose && result)
				printf("Cannot open HID device interface.\n");

			getDeviceInfo(hidDevice, hidProperties, deviceRec);
			CFRelease(hidProperties);
		}
		else if (verbose)
			printf("Cannot get device properties.\n");
	}
	else if (verbose)
		printf("Cannot get memory for device record.\n");

	return deviceRec;
}
void InterfaceManagerImpl::handleNetManagerSignal(const std::string &signalName, GVariant *params)
{
     unique_lock lock(mMutex);

     try
     {             
         if(signalName == NM_SIGNAL_DEVICE_ADDED || signalName == NM_SIGNAL_DEVICE_REMOVED )
         {
             const char *devPath;
             g_variant_get_child (params, 0, "&o", &devPath);

             if(signalName == NM_SIGNAL_DEVICE_ADDED)
             {
                 InterfaceInfo info = getDeviceInfo(devPath);
                 mInterfaces.insert(InterfaceInfoPair(devPath, info));
                 interfaceListUpdateSignal(info, true);
             }
             else if(signalName == NM_SIGNAL_DEVICE_REMOVED)
             {

                 auto info = mInterfaces.find(devPath);
                 if(info != mInterfaces.end())
                 {
                     InterfaceInfo devInfo = info->second;
                     mInterfaces.erase(devPath);
                     interfaceListUpdateSignal(devInfo, false);
                 }
             }
         }
     }
     catch(const std::exception& e){
         updateFailedSignal();
     }
}
Пример #3
0
/***************************************************************************************************
*FunctionName: SystemReset
*Description: 恢复出厂设置
*Input: 
*Output: 
*Return: 
*Author: xsx
*Date: 2017年2月16日11:20:46
***************************************************************************************************/
MyState_TypeDef SystemReset(void)
{
	SystemSetData * systemSetData = NULL;
	
	systemSetData = MyMalloc(sizeof(SystemSetData));
	if(systemSetData)
	{
		//恢复默认
		setDefaultSystemSetData(systemSetData);
		//保留设备信息
		getDeviceInfo(&(systemSetData->deviceInfo));
		//保留已校准的led值
		systemSetData->testLedLightIntensity = getTestLedLightIntensity(getGBSystemSetData());

		if(My_Pass != SaveSystemSetData(systemSetData))
			return My_Fail;
	}
	else
		return My_Fail;
	
	//删除操作人
	if(My_Fail == ClearUsers())
		return My_Fail;
	
	//删除wifi数据
	if(My_Fail == ClearWifi())
		return My_Fail;
	
	return My_Pass;
}
	void open(unsigned int port)
	{
		const std::string devicePath = getDevicePath(port);

		if (devicePath.empty())
		{
			throw IOException(Poco::format("Failed to open usb port (index: %u).\n"
			                                       "USB Interface not exist or already opened", port));
		}

		handle_ = hid_open_path(devicePath.c_str());
		if (!handle_)
		{
			throw IOException(Poco::format("Failed to open usb port (index: %u).\n"
			                                       "USB Interface not exist or already opened", port));
		}

		port_ = port;

		const UsbDeviceInfo& deviceInfo = getDeviceInfo(port);
		vendorId_ = deviceInfo.getVendorId();
		productId_ = deviceInfo.getProductId();
		manufacturer_ = deviceInfo.getManufacturer();
		product_ = deviceInfo.getProduct();
		serialNumber_ = deviceInfo.getSerialNumber();
	}
Пример #5
0
void ClWrapper::printOpenCLInfo()
{
  std::cout << getPlatformInfo(CL_PLATFORM_VERSION) << std::endl;

  cl_uint* max_compute_units = (cl_uint*)getDeviceInfo(CL_DEVICE_MAX_COMPUTE_UNITS);
  std::cout << "Max compute units: " << *max_compute_units << std::endl;
}
Пример #6
0
size_t DeviceManagerPulseAudio::getNumOutputChannels( const DeviceRef &device )
{
	auto& devInfo = getDeviceInfo( device );
	if( devInfo.mUsage != DeviceInfo::Usage::OUTPUT ) {
		return 0;
    }

	return devInfo.mNumChannels;	
}
Пример #7
0
int getHardwareIdInfo() {
	setRunParamUrnHardwareId(onvifRunParam.hardwareId);
	OnvifDeviceInfo onvifDeviceInfo;
	int result = getDeviceInfo(&onvifDeviceInfo);
	if (!isRetCodeSuccess(result)) {
		logInfo("Get Device Info Error");
		return result;
	}

	return RET_CODE_SUCCESS;
}
Пример #8
0
//---------------------------------------------------------------------------
bool TRig::openOak(void)
{
 EOakStatus status;
 unsigned int rate = 100;

   if(isOakOpen())
       return true;

   if(oak_device.isEmpty()) {
       qDebug("Empty path to HID device");

       return false;
   }

   if(!checkOak(openDevice(oak_device.toStdString(), oakHandle)))
       return false;

   if(!checkOak(getDeviceInfo(oakHandle, oakDevInfo)))
       return false;
   else if(oakDevInfo.numberOfChannels < 4) {
       qDebug("Inclinometer should have 4 channels found %d", oakDevInfo.numberOfChannels);
       closeOak();

       return false;
   }

   // Set the report Mode
   if(!checkOak(setReportMode(oakHandle, eReportModeAfterSampling, true)))
   //if(!checkOak(setReportMode(oakHandle, eReportModeFixedRate, true)))
   //if(!checkOak(setReportMode(oakHandle, eReportModeAfterChange, true)))
       return false;

   // Set the report rate
   // This parameter will only be regarded if Report Mode = 2 (fixed rate)
   if(!checkOak(setReportRate(oakHandle, rate, true)))
       return false;

   // Set the sample rate
   if(!checkOak(setSampleRate(oakHandle, rate, true)))
   //if(!checkOak(setSampleRate(oakHandle, rate * 2, true)))
       return false;

   // get channel 3 (zenith angle) info
   status = getChannelInfo(oakHandle, 2, oakChannelInfo[0]);
   // get channel 4 (azimuth angle) info
   if(status == eOakStatusOK)
      status = getChannelInfo(oakHandle, 3, oakChannelInfo[1]);

   if(!checkOak(status))
       return false;

 return true;
}
Пример #9
0
void MtpDevice::initialize() {
    openSession();
    mDeviceInfo = getDeviceInfo();
    if (mDeviceInfo) {
        if (mDeviceInfo->mDeviceProperties) {
            int count = mDeviceInfo->mDeviceProperties->size();
            for (int i = 0; i < count; i++) {
                MtpDeviceProperty propCode = (*mDeviceInfo->mDeviceProperties)[i];
                MtpProperty* property = getDevicePropDesc(propCode);
                if (property)
                    mDeviceProperties.push(property);
            }
        }
    }
}
Пример #10
0
string GraphDog::getToken(){
	
    string udid=getUdid();
    string auid=getAuID();
    string email=getEmail();
    string nick=getNick();
    string flag=getFlag();
    string lang=getLanguage();
    string platform=getPlatform();
    string cTime=getCTime();
    string dInfo=getDeviceInfo();
    string token=GraphDogLib::GDCreateToken(auid,udid,flag,lang,nick,email,platform,cTime,sKey,dInfo);
//	CCLog("%s", token.c_str());
//	CCLog("%s", unBase64NextUnDes("GDSK3388", token).c_str());
    return token;
}
Пример #11
0
BOOL openDevice(bool handleError)
{
	if (!getDeviceInfo(&KSCATEGORY_TOPOLOGY, &cmiTopologyDev)) {
		if (handleError)
			PrintLastError("getDeviceInfo()");
		return FALSE;
	}

	if (!getDeviceInterfaceDetail(&KSCATEGORY_TOPOLOGY, &cmiTopologyDev)) {
		if (handleError)
			PrintLastError("getDeviceInterfaceDetail()");
		return FALSE;
	}

	return TRUE;
}
Пример #12
0
	void Platform::getPlatformInfo( cl_platform_id id )
	{
		char platformName[256];
		char platformVendor[256];
		char platformVersion[256];
		char platformProfile[256];

		clGetPlatformInfo( id, CL_PLATFORM_NAME, 256, platformName, 0 );
		clGetPlatformInfo( id, CL_PLATFORM_VENDOR, 256, platformVendor, 0 );
		clGetPlatformInfo( id, CL_PLATFORM_VERSION, 256, platformVersion, 0 );
		clGetPlatformInfo( id, CL_PLATFORM_PROFILE, 256, platformProfile, 0 );

		std::cout << "Name: " << platformName << std::endl;
		std::cout << "Vendor: " << platformVendor << std::endl;
		std::cout << "Version: " << platformVersion << std::endl;
		std::cout << "Profile: " << platformProfile << std::endl;

		getDeviceInfo( id );
	}
Пример #13
0
/*****************************************************************************
 * oak_digin_setup(..)
 *****************************************************************************/
int oak_digin_setup(int* deviceHandle, char* oakDiginDevice)
{
  int oak_stat;

  oak_stat = CHECK_OAK_CALL(openDevice(oakDiginDevice, deviceHandle));
  if (oak_stat != 0) return oak_stat;

  // get the device informations
  oak_stat = CHECK_OAK_CALL(getDeviceInfo(oakDiginHandle, &devInfo));
  if (oak_stat != 0) return oak_stat;

/*   fprintf( stderr, "oak_digin_setup: Oak device: %s\n", devInfo.deviceName); */
/*   fprintf( stderr, "oak_digin_setup: Volatile user device name: %s\n", devInfo.volatileUserDeviceName); */
/*   fprintf( stderr, "oak_digin_setup: Persistent user device name: %s\n", devInfo.persistentUserDeviceName); */
/*   fprintf( stderr, "oak_digin_setup: Serial number: %s\n", devInfo.serialNumber); */
/*   fprintf( stderr, "oak_digin_setup: VendorID: 0x%.4x :: ProductID: 0x%.4x :: Version 0x%.4x\n", devInfo.vendorID, devInfo.productID, devInfo.version); */
/*   fprintf( stderr, "oak_digin_setup: Number of channels: %d\n", devInfo.numberOfChannels); */

  if (strcmp(devInfo.deviceName, "Toradex Optical Isolated Input")) {
    return -1;
  }
  // Set the LED Mode to indicate initialize state
  oak_stat = CHECK_OAK_CALL( setLedMode(*deviceHandle, eLedModeBlinkFast, false));
  if (oak_stat != 0) return oak_stat;

  // Set the report Mode
  oak_stat = CHECK_OAK_CALL(setReportMode(*deviceHandle, eReportModeAfterSampling, false));

  if (oak_stat != 0) return oak_stat;

  // Set the sample rate
  oak_stat = CHECK_OAK_CALL( setSampleRate(*deviceHandle, 50, false));
  if (oak_stat != 0) return oak_stat;

  // Retrieve Channel infos
  /* wildi ToDo
   * ChannelInfo* channelInfos = xmalloc(devInfo.numberOfChannels *sizeof(ChannelInfo));
   * ChannelInfo* chanInfo;
   * chanInfo = &channelInfos[1];
  */
  return 0;
}
Пример #14
0
Файл: ocl.c Проект: cran/OpenCL
SEXP ocl_get_device_info(SEXP device) {
    SEXP res;
    cl_device_id device_id = getDeviceID(device);
    const char *names[] = { "name", "vendor", "version", "profile", "exts", "driver.ver" };
    SEXP nv = PROTECT(Rf_allocVector(STRSXP, 6));
    int i;
    for (i = 0; i < LENGTH(nv); i++) SET_STRING_ELT(nv, i, mkChar(names[i]));
    res = PROTECT(Rf_allocVector(VECSXP, LENGTH(nv)));
    Rf_setAttrib(res, R_NamesSymbol, nv);
    SET_VECTOR_ELT(res, 0, getDeviceInfo(device_id, CL_DEVICE_NAME));
    SET_VECTOR_ELT(res, 1, getDeviceInfo(device_id, CL_DEVICE_VENDOR));
    SET_VECTOR_ELT(res, 2, getDeviceInfo(device_id, CL_DEVICE_VERSION));
    SET_VECTOR_ELT(res, 3, getDeviceInfo(device_id, CL_DEVICE_PROFILE));
    SET_VECTOR_ELT(res, 4, getDeviceInfo(device_id, CL_DEVICE_EXTENSIONS));
    SET_VECTOR_ELT(res, 5, getDeviceInfo(device_id, CL_DRIVER_VERSION));
    UNPROTECT(2);
    return res;
}
void InterfaceManagerImpl::updateDevices()
{
    unique_lock(mMutex);

    GVariant* deviceList = nullptr;
    GError* error = nullptr;
    GCancellable* c = nullptr;

    try
    {
        if(mNetManagerProxy == nullptr){
            throw std::runtime_error("Network Manager proxy not initialized");
        }

        deviceList = g_dbus_proxy_call_sync(mNetManagerProxy,
                                            NM_METHOD_GET_DEVICES,
                                            NULL,
                                            G_DBUS_CALL_FLAGS_NONE,
                                            1000, //timout of operation
                                            c,
                                            &error);


        if (deviceList == NULL && error != NULL){
            throw std::runtime_error(error->message);
        }

        /**< iteration through the list */
        GVariantIter deviceIter1, deviceIter2;
        GVariant *deviceNode1, *deviceNode2;

        g_variant_iter_init(&deviceIter1, deviceList);
        while ((deviceNode1 = g_variant_iter_next_value(&deviceIter1)))
        {
            g_variant_iter_init(&deviceIter2, deviceNode1);
            while ((deviceNode2 = g_variant_iter_next_value(&deviceIter2)))
            {
                gsize strlength = 256;
                const gchar* devicePath = g_variant_get_string(deviceNode2, &strlength);
                InterfaceInfo info = getDeviceInfo(devicePath);
                mInterfaces.insert(InterfaceInfoPair(devicePath, info));
            }
        }                
    }
    catch(const std::exception& e)
    {
        if(deviceList != nullptr){
            g_variant_unref(deviceList);
        }

        if(error != nullptr){
            g_error_free(error);
        }

        if(c != nullptr){
            g_cancellable_release_fd(c);
        }

        std::cout<<e.what()<<std::endl;
        updateFailedSignal();
    }
}
Пример #16
0
std::string DeviceManagerPulseAudio::getName( const DeviceRef &device )
{
	return getDeviceInfo( device ).mName;	
}
Пример #17
0
size_t DeviceManagerPulseAudio::getSampleRate( const DeviceRef &device )
{
	return getDeviceInfo( device ).mSampleRate;	
}
Пример #18
0
int clPeak::runAll()
{
    try
    {

#ifdef USE_STUB_OPENCL
        stubOpenclReset();
#endif
        vector<cl::Platform> platforms;
        cl::Platform::get(&platforms);

        log->xmlOpenTag("clpeak");
        log->xmlAppendAttribs("os", OS_NAME);
        bool isComputeInt_saved = isComputeInt;
        bool isComputeDP_saved = isComputeDP;
        for(int p=0; p < (int)platforms.size(); p++)
        {
            if(forcePlatform && (p != specifiedPlatform))
                continue;

            isComputeInt = isComputeInt_saved;
            isComputeDP = isComputeDP_saved;

            log->print(NEWLINE "Platform: " + platforms[p].getInfo<CL_PLATFORM_NAME>() + NEWLINE);
            log->xmlOpenTag("platform");
            log->xmlAppendAttribs("name", platforms[p].getInfo<CL_PLATFORM_NAME>());

            cl_context_properties cps[3] = {
                    CL_CONTEXT_PLATFORM,
                    (cl_context_properties)(platforms[p])(),
                    0
                };
            cl::Context ctx(CL_DEVICE_TYPE_ALL, cps);
            vector<cl::Device> devices = ctx.getInfo<CL_CONTEXT_DEVICES>();

            string plaformName = platforms[p].getInfo<CL_PLATFORM_NAME>();
            bool isIntel = (plaformName.find("Intel") != std::string::npos)? true: false;
            bool isPocl = (plaformName.find("Portable Computing Language") != std::string::npos)? true: false;
            bool isApple = (plaformName.find("Apple") != std::string::npos)? true: false;

            cl::Program prog;

            // FIXME Disabling integer compute tests on intel platform
            // Kernel build is taking much much longer time
            // FIXME Disabling integer compute tests on apple platform
            // Causes Segmentation fault: 11
            if(isIntel || isApple) {
                cl::Program::Sources source(1, make_pair(stringifiedKernelsNoInt, (strlen(stringifiedKernelsNoInt)+1)));
                isComputeInt = false;
                prog = cl::Program(ctx, source);
            } else {
                cl::Program::Sources source(1, make_pair(stringifiedKernels, (strlen(stringifiedKernels)+1)));
                prog = cl::Program(ctx, source);
            }

            // FIXME Disable compute-dp & comute-integer tests for pocl
            // DP test segfaults & integer test takes infinite time in llc step
            if(isPocl)
            {
                isComputeDP = false;
                isComputeInt = false;
            }

            for(int d=0; d < (int)devices.size(); d++)
            {
                if(forceDevice && (d != specifiedDevice))
                    continue;

                device_info_t devInfo = getDeviceInfo(devices[d]);

                log->print(TAB "Device: " + devInfo.deviceName + NEWLINE);
                log->print(TAB TAB "Driver version  : ");
                log->print(devInfo.driverVersion);  log->print(" (" OS_NAME ")" NEWLINE);
                log->print(TAB TAB "Compute units   : ");
                log->print(devInfo.numCUs);         log->print(NEWLINE);
                log->print(TAB TAB "Clock frequency : ");
                log->print(devInfo.maxClockFreq);   log->print(" MHz" NEWLINE);
                log->xmlOpenTag("device");
                log->xmlAppendAttribs("name", devInfo.deviceName);
                log->xmlAppendAttribs("driver_version", devInfo.driverVersion);
                log->xmlAppendAttribs("compute_units", devInfo.numCUs);
                log->xmlAppendAttribs("clock_frequency", devInfo.maxClockFreq);
                log->xmlAppendAttribs("clock_frequency_unit", "MHz");

                try {
                    vector<cl::Device> dev = {devices[d]};
                    prog.build(dev, BUILD_OPTIONS);
                 }
                 catch (cl::Error error)
                 {
                    log->print(TAB TAB "Build Log: " + prog.getBuildInfo<CL_PROGRAM_BUILD_LOG>(devices[d])
                                        + NEWLINE NEWLINE);
                    continue;
                 }

                cl::CommandQueue queue = cl::CommandQueue(ctx, devices[d], CL_QUEUE_PROFILING_ENABLE);

                runGlobalBandwidthTest(queue, prog, devInfo);
                runComputeSP(queue, prog, devInfo);
                runComputeDP(queue, prog, devInfo);
                runComputeInteger(queue, prog, devInfo);
                runTransferBandwidthTest(queue, prog, devInfo);
                runKernelLatency(queue, prog, devInfo);

                log->print(NEWLINE);
                log->xmlCloseTag();       // device
            }
            log->xmlCloseTag();           // platform
        }
        log->xmlCloseTag();               // clpeak
    }
    catch(cl::Error error)
    {
        stringstream ss;
        ss << error.what() << " (" << error.err() << ")" NEWLINE;

        log->print(ss.str());
        return -1;
    }

    return 0;
}
Пример #19
0
size_t DeviceManagerPulseAudio::getFramesPerBlock( const DeviceRef &device )
{
	size_t frames = getDeviceInfo( device ).mFramesPerBlock;
	return frames;	
}
Пример #20
0
int main()
{
	unsigned long int i, j; /* jokers */
	unsigned long long int k; /* another joker */
	int err;
	
	extern unsigned long int totalNodes; /* declared in loadNGCE.c */
	timexStart();
	node *graph = parseNGCEoutput(GRAPH_PATH, &err); /* create graph */
	if  (graph == NULL)
		return EXIT_FAILURE;
	fprintf(stdout, "Took %4.2f seconds to load graph from file\n", timexGet());

#ifdef COMPUTE_C
	/* computing betweness centrality on cpu */
	fprintf(stdout, "Computing shortest paths and betweeness centrality on cpu, coded in c\n");
	timexStart();
	signed long long int **computedSP = malloc(totalNodes * sizeof(signed long long int *));
	signed long long int pathLength;
	for (i = 0; i < totalNodes; i++)
	{
		computedSP[i] = malloc(totalNodes * sizeof(signed long long int)); /* initialization */
		for (j = 0; j < totalNodes; j++)
		{
			if (i == j)
				computedSP[i][j] = 0; /* 0 distance to self */
			else
				computedSP[i][j] = -1; /* unexplored path */
		}
	}
	
	for (i = 0; i < totalNodes; i++)
		for (j = 0; j < totalNodes; j++)
			if (computedSP[i][j] == -1) /* not known */
			{			
				if ((graph[i].peerCount == 0) || (graph[j].peerCount ==0))
				{} /* oops. no connection */
				else
					pathLength = shortestPath(&graph[i], &graph[j], graph); /* calculate */
				
				computedSP[i][j] = pathLength; /* set this */
				computedSP[j][i] = pathLength; /* and reverse to result */
			}
	fprintf(stdout, "Took %2f seconds to compute shortest paths and betweeness centrality\n", timexGet());
	
	#ifdef DEBUG_OUTPUT
		for (i = 0; i < totalNodes; i++)
			fprintf(stdout, "Node %4lu has a betweeness centrality of %4lu\n", graph[i].name, graph[i].spCount);
	#endif
	
#endif
	
#ifdef COMPUTE_OPENCL
	/* creating all shortest paths-pairs */
	k = 0;
	pair *all = malloc(totalNodes * 3 * sizeof(pair));
	for (i = 0; i < totalNodes; i++)
		for (j = 0; j < totalNodes; j++, k++)
		{
			all[k].a = i;
			all[k].b = j;
		}	
	
	/* choosing compute device */
	cl_device_id *devID = malloc(sizeof(cl_device_id));
	devID = availClDevices(&err);
	
	#ifdef DEBUG_OUTPUT
		clDeviceSpecs info;
		err = getDeviceInfo(&info, devID);
		fprintf(stdout, "%s:%d: Working on: %s %s. Memory: %lluM. Work items: %zu. Compute units: %d. Local memory (cache): %lluM. Maximum malloc: %lluM\n",
			__FILE__, __LINE__, info.vendor, info.name, info.memory/1024/1024, info.workGroupSize, info.compUnits, info.localMemory/1024/1024, info.maxMalloc/1024/1024);
	#endif	
	
	/* demo loading kernel source from text file */
	char *fnSource = readKernelSource(KERNEL_FILE, &err);
	char **kernelSource = malloc(sizeof(char *)); /* opencl bs */
	kernelSource[0] = fnSource;
	if (err != READSOURCE_OK)
	{
		free(graph);
		return EXIT_FAILURE;
	}		
	#ifdef DEBUG_OUTPUT
		fprintf(stdout, "%s:%d: Kernel source code following:\n%s\n", __FILE__, __LINE__, fnSource);
	#endif
	
	/* the context */
	cl_context context;
	context = clCreateContext(0, 1, devID, NULL, NULL, &err);
	if (err != CL_SUCCESS)
	{
		fprintf(stderr, "%s:%d: Error creating context: %s\n", __FILE__, __LINE__, strerrorCL(&err));
		return EXIT_FAILURE;
	}

	/* the command queue */
	cl_command_queue commands;
	commands = clCreateCommandQueue(context, *devID, 0, &err);
    if (!commands)
    {
        fprintf(stderr, "%s:%d: Error creating command queue: %s\n", __FILE__, __LINE__, strerrorCL(&err));
        return EXIT_FAILURE;
    }

	/* the actual program, checking */
	cl_program program;
	program = clCreateProgramWithSource(context, 1, (const char **) kernelSource, NULL, &err);
    if (!program)
    {
        fprintf(stderr, "%s:%d: Error creating program: %s\n", __FILE__, __LINE__, strerrorCL(&err));
        return EXIT_FAILURE;
    }
	
	/* the actual program, building */
	err = clBuildProgram(program, 1, devID, NULL, NULL, NULL); /* clBuildProgam(program, 0, NULL, NULL, NULL, NULL); */
    if (err != CL_SUCCESS)
    {
        size_t len;
        char buffer[2048];
		
        fprintf(stderr, "%s:%d: Error building program executable: %s\n", __FILE__, __LINE__, strerrorCL(&err));
        clGetProgramBuildInfo(program, *devID, CL_PROGRAM_BUILD_LOG, sizeof(buffer), buffer, &len);
        fprintf(stderr, "%s:%d: Build log following: %s\n", __FILE__, __LINE__, buffer);
        return EXIT_FAILURE;
    }
	
	/* the kernel */
	cl_kernel kernel;
	kernel = clCreateKernel(program, "betweeness", &err);
	/* cl_kernel clCreateKernel(cl_program program, const char *kernel_name, cl_int *errcode_ret) */	 
    if (!kernel || err != CL_SUCCESS)
    {
        fprintf(stderr, "%s:%d: Error creating compute kernel: %s\n", __FILE__, __LINE__, strerrorCL(&err));
        return EXIT_FAILURE;
    }

	cl_mem inputGraph;
	cl_mem inputPairs;
    cl_mem outputLengths;
	size_t inputGraphSize = sizeof(node) * totalNodes;
	size_t inputPairsSize = sizeof(pair) * totalNodes * 3;
	size_t outputLengthsSize = sizeof(unsigned long int) * totalNodes;
	inputGraph = clCreateBuffer(context,  CL_MEM_READ_ONLY,  inputGraphSize, NULL, NULL);
	inputPairs = clCreateBuffer(context, CL_MEM_READ_ONLY, inputPairsSize, NULL, NULL);
    outputLengths = clCreateBuffer(context, CL_MEM_WRITE_ONLY, outputLengthsSize, NULL, NULL);
    if (!inputGraph || !inputPairs || !outputLengths)
    {
        fprintf(stderr, "%s:%d: Error allocating device memory: %s\n", __FILE__, __LINE__, strerrorCL(&err));
        return EXIT_FAILURE;
    }    
    
    err = clEnqueueWriteBuffer(commands, inputGraph, CL_TRUE, 0, inputGraphSize, graph, 0, NULL, NULL);
    if (err != CL_SUCCESS)
    {
        fprintf(stderr, "%s:%d: Error writing to source array: %s\n", __FILE__, __LINE__, strerrorCL(&err));
        return EXIT_FAILURE;
    }
	
	err = clEnqueueWriteBuffer(commands, inputPairs, CL_TRUE, 0, inputPairsSize, all, 0, NULL, NULL);
    if (err != CL_SUCCESS)
    {
        fprintf(stderr, "%s:%d: Error writing to source array: %s\n", __FILE__, __LINE__, strerrorCL(&err));
        return EXIT_FAILURE;
    }
	
    err = 0;
    err  = clSetKernelArg(kernel, 0, sizeof(cl_mem), &inputGraph);
	err  = clSetKernelArg(kernel, 1, sizeof(cl_mem), &inputPairs);
    err |= clSetKernelArg(kernel, 2, sizeof(cl_mem), &outputLengths);
    err |= clSetKernelArg(kernel, 3, sizeof(unsigned long int), &totalNodes);
    if (err != CL_SUCCESS)
    {
        fprintf(stderr, "%s:%d: Error setting kernela arguments: %s\n", __FILE__, __LINE__, strerrorCL(&err));
        return EXIT_FAILURE;
    }
	
	size_t local;
    err = clGetKernelWorkGroupInfo(kernel, *devID, CL_KERNEL_WORK_GROUP_SIZE, sizeof(local), &local, NULL);
    if (err != CL_SUCCESS)
    {
        fprintf(stderr, "%s:%d: Error retrieving kernel work group info: %s\n", __FILE__, __LINE__, strerrorCL(&err));
        return EXIT_FAILURE;
    }
	
    unsigned long long int global = totalNodes * 3;
    err = clEnqueueNDRangeKernel(commands, kernel, 1, NULL, &global, NULL, 0, NULL, NULL);
    if (err)
    {
		fprintf(stderr, "%s:%d: Error executing kernel: %s\n", __FILE__, __LINE__, strerrorCL(&err));
        return EXIT_FAILURE;
    }
	
    clFinish(commands);
	
	unsigned long int *betw = malloc(totalNodes * sizeof(unsigned long int));
    err = clEnqueueReadBuffer( commands, outputLengths, CL_TRUE, 0, sizeof(unsigned long int) * totalNodes, betw, 0, NULL, NULL );  
    if (err != CL_SUCCESS)
    {
        printf("Error: Failed to read output array! %d\n", err);
        exit(1);
    }
	
	
	for (i = 0; i < totalNodes; i++)
		printf("computed a betweeness centrality of: %lu\n", betw[i]);
		
	free(graph);
	free(devID);
	free(kernelSource);
//	free(computedSP);
#endif
	
	return EXIT_SUCCESS;
}
Пример #21
0
void test_GetDeviceInfo() {
	OnvifDeviceInfo onvifDeviceInfo;
	TEST_ASSERT_EQUAL(RET_CODE_SUCCESS, getDeviceInfo(&onvifDeviceInfo));
}
Пример #22
0
void DeviceManagerPulseAudio::setSampleRate( const DeviceRef &device, size_t sampleRate )
{
	getDeviceInfo( device ).mSampleRate = sampleRate;
	emitParamsDidChange( device );
}
Пример #23
0
void DeviceManagerPulseAudio::setFramesPerBlock( const DeviceRef &device, size_t framesPerBlock )
{
	getDeviceInfo( device ).mFramesPerBlock = framesPerBlock;
	emitParamsDidChange( device );
}
void ChangeJournalWatcher::watchDir(const std::wstring &dir)
{
	WCHAR volume_path[MAX_PATH]; 
	BOOL ok = GetVolumePathNameW(dir.c_str(), volume_path, MAX_PATH);
	if(!ok)
	{
		Server->Log("GetVolumePathName(dir, volume_path, MAX_PATH) failed in ChangeJournalWatcher::watchDir", LL_ERROR);
		listener->On_ResetAll(dir);
		has_error=true;
		error_dirs.push_back(dir);
		return;
	}

	std::wstring vol=volume_path;

	if(vol.size()>0)
	{
		if(vol[vol.size()-1]=='\\')
		{
			vol.erase(vol.size()-1,1);
		}
	}

	std::map<std::wstring, SChangeJournal>::iterator it=wdirs.find(vol);
	if(it!=wdirs.end())
	{
		it->second.path.push_back(dir);
		return;
	}

	bool do_index=false;

	_i64 rid=hasRoot(vol);
	if(rid==-1)
	{
		listener->On_ResetAll(vol);
		do_index=true;
		rid=addRoot(vol);
		setIndexDone(vol, 0);
	}

	HANDLE hVolume=CreateFileW((L"\\\\.\\"+vol).c_str(), GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
	if(hVolume==INVALID_HANDLE_VALUE)
	{
		Server->Log(L"CreateFile of volume '"+vol+L"' failed. - watchDir", LL_ERROR);
		listener->On_ResetAll(vol);
		error_dirs.push_back(vol);
		CloseHandle(hVolume);
		has_error=true;
		return;
	}
	
	USN_JOURNAL_DATA data;
	DWORD r_bytes;
	BOOL b=DeviceIoControl(hVolume, FSCTL_QUERY_USN_JOURNAL, NULL, 0, &data, sizeof(USN_JOURNAL_DATA), &r_bytes, NULL);
	if(b==0)
	{
		DWORD err=GetLastError();
		if(err==ERROR_INVALID_FUNCTION)
		{
			Server->Log(L"Change Journals not supported for Volume '"+vol+L"'", LL_ERROR);
			listener->On_ResetAll(vol);
			error_dirs.push_back(vol);
			CloseHandle(hVolume);
			has_error=true;
			return;
		}
		else if(err==ERROR_JOURNAL_DELETE_IN_PROGRESS)
		{
			Server->Log(L"Change Journals for Volume '"+vol+L"' is being deleted", LL_ERROR);
			listener->On_ResetAll(vol);
			error_dirs.push_back(vol);
			CloseHandle(hVolume);
			has_error=true;
			return;
		}
		else if(err==ERROR_JOURNAL_NOT_ACTIVE)
		{
			CREATE_USN_JOURNAL_DATA dat;
			dat.AllocationDelta=10485760; //10 MB
			dat.MaximumSize=73400320; // 70 MB
			DWORD bret;
			BOOL r=DeviceIoControl(hVolume, FSCTL_CREATE_USN_JOURNAL, &dat, sizeof(CREATE_USN_JOURNAL_DATA), NULL, 0, &bret, NULL);
			if(r==0)
			{
				Server->Log(L"Error creating change journal for Volume '"+vol+L"'", LL_ERROR);
				listener->On_ResetAll(vol);
				error_dirs.push_back(vol);
				CloseHandle(hVolume);
				has_error=true;
				return;
			}
			b=DeviceIoControl(hVolume, FSCTL_QUERY_USN_JOURNAL, NULL, 0, &data, sizeof(USN_JOURNAL_DATA), &r_bytes, NULL);
			if(b==0)
			{
				Server->Log(L"Unknown error for Volume '"+vol+L"' after creation - watchDir", LL_ERROR);
				listener->On_ResetAll(vol);
				error_dirs.push_back(vol);
				CloseHandle(hVolume);
				has_error=true;
				return;
			}
		}
		else
		{
			Server->Log(L"Unknown error for Volume '"+vol+L"' - watchDir ec: "+convert((int)err), LL_ERROR);
			listener->On_ResetAll(vol);
			error_dirs.push_back(vol);
			CloseHandle(hVolume);
			has_error=true;
			return;
		}
	}

	SDeviceInfo info=getDeviceInfo(vol);

	if(info.has_info)
	{
		if(info.journal_id!=data.UsnJournalID)
		{
			Server->Log(L"Journal id for '"+vol+L"' wrong - reindexing", LL_WARNING);
			listener->On_ResetAll(vol);
			do_index=true;
			setIndexDone(vol, 0);
			info.last_record=data.NextUsn;

			q_update_journal_id->Bind((_i64)data.UsnJournalID);
			q_update_journal_id->Bind(vol);
			q_update_journal_id->Write();
			q_update_journal_id->Reset();
		}

		bool needs_reindex=false;

		if( do_index==false && (info.last_record<data.FirstUsn || info.last_record>data.NextUsn) )
		{
			Server->Log(L"Last record not readable at '"+vol+L"' - reindexing", LL_WARNING);
			needs_reindex=true;
		}

		if( do_index==false && data.NextUsn-info.last_record>usn_reindex_num )
		{
			Server->Log(L"There are "+convert(data.NextUsn-info.last_record)+L" new USN entries at '"+vol+L"' - reindexing", LL_WARNING);
			needs_reindex=true;
		}

		if(needs_reindex)
		{
			
			listener->On_ResetAll(vol);
			do_index=true;
			setIndexDone(vol, 0);
			info.last_record=data.NextUsn;
		}

		if(do_index==false && info.index_done==0)
		{
			Server->Log(L"Indexing was not finished at '"+vol+L"' - reindexing", LL_WARNING);
			do_index=true;
			setIndexDone(vol, 0);
			info.last_record=data.NextUsn;
		}
	}
	else
	{
		listener->On_ResetAll(vol);
		Server->Log(L"Info not found at '"+vol+L"' - reindexing", LL_WARNING);
		do_index=true;
	}

	SChangeJournal cj;
	cj.journal_id=data.UsnJournalID;
	if(!info.has_info)
		cj.last_record=data.NextUsn;
	else
		cj.last_record=info.last_record;

	cj.path.push_back(dir);
	cj.hVolume=hVolume;
	cj.rid=rid;
	cj.last_record_update=false;
	cj.vol_str=vol;

	if(!info.has_info)
	{
		q_add_journal->Bind((_i64)data.UsnJournalID);
		q_add_journal->Bind(vol);
		q_add_journal->Bind(cj.last_record);
		q_add_journal->Write();
		q_add_journal->Reset();

		setIndexDone(vol, 0);
	}

	wdirs.insert(std::pair<std::wstring, SChangeJournal>(vol, cj) );

	if(do_index)
	{
		reindex(rid, vol, &cj);
		Server->Log(L"Reindexing of '"+vol+L"' done.", LL_INFO);
	}
}