/** * Allocate an virtual slave device for xtest events, this * is a slave device to inputInfo master devices */ void InitXTestDevices(void) { if(AllocXTestDevice(serverClient, "Virtual core", &xtestpointer, &xtestkeyboard, inputInfo.pointer, inputInfo.keyboard) != Success) FatalError("Failed to allocate XTest devices"); if (ActivateDevice(xtestpointer, TRUE) != Success || ActivateDevice(xtestkeyboard, TRUE) != Success) FatalError("Failed to activate XTest core devices."); if (!EnableDevice(xtestpointer, TRUE) || !EnableDevice(xtestkeyboard, TRUE)) FatalError("Failed to enable XTest core devices."); AttachDevice(NULL, xtestpointer, inputInfo.pointer); AttachDevice(NULL, xtestkeyboard, inputInfo.keyboard); }
GpuDevice::Impl::~Impl() { ActivateDevice(); for (size_t i = 0; i < kParallelism; ++i) { CUDNN_CALL(cudnnDestroy(cudnn_handle[i])); CUBLAS_CALL(cublasDestroy(cublas_handle[i])); CUDA_CALL(cudaStreamDestroy(stream[i])); } }
GpuDevice::Impl::Impl(int d) : device(d) { ActivateDevice(); for (size_t i = 0; i < kParallelism; ++i) { CUDA_CALL(cudaStreamCreate(&stream[i])); CUBLAS_CALL(cublasCreate(&cublas_handle[i])); CUBLAS_CALL(cublasSetStream(cublas_handle[i], stream[i])); CUDNN_CALL(cudnnCreate(&cudnn_handle[i])); CUDNN_CALL(cudnnSetStream(cudnn_handle[i], stream[i])); } }
int main(int argc, char *argv[]) { int err = 0; if(argc < 2) return 0; if(strstr(argv[1], "list") != NULL) { err = GetDeviceList(); if(err < 0) { fprintf(stderr, "GetDeviceList error:%d\n", err); } return 0; } else if(strstr(argv[1], "download") != NULL) { if(argc < 3) return 0; err = DownfwDevice(argv[2], argv[3]); if(err < 0) fprintf(stderr, "DownfwDevice error:%d\n", err); return 0; } else if(strstr(argv[1], "format") != NULL) { err = FormatDevice(argv[2]); if(err < 0) fprintf(stderr, "format error:%d\n", err); return 0; } else if(strstr(argv[1], "activate") != NULL) { if (argc < 5){ printf("argc not is 5\n"); return 0; } int slot = (argv[3][0]) - 48; int action = (argv[4][0]) - 48; err = ActivateDevice(argv[2], slot, action); if(err < 0) fprintf(stderr, "activate error:%d\n", err); return 0; } else { printf("args error\n"); } return 0; }
static int add_master(ClientPtr client, xXIAddMasterInfo *c, int flags[MAXDEVICES]) { DeviceIntPtr ptr, keybd, XTestptr, XTestkeybd; char* name; int rc; name = calloc(c->name_len + 1, sizeof(char)); strncpy(name, (char*)&c[1], c->name_len); rc = AllocDevicePair(client, name, &ptr, &keybd, CorePointerProc, CoreKeyboardProc, TRUE); if (rc != Success) goto unwind; if (!c->send_core) ptr->coreEvents = keybd->coreEvents = FALSE; /* Allocate virtual slave devices for xtest events */ rc = AllocXTestDevice(client, name, &XTestptr, &XTestkeybd, ptr, keybd); if (rc != Success) { DeleteInputDeviceRequest(ptr); DeleteInputDeviceRequest(keybd); goto unwind; } ActivateDevice(ptr, FALSE); ActivateDevice(keybd, FALSE); flags[ptr->id] |= XIMasterAdded; flags[keybd->id] |= XIMasterAdded; ActivateDevice(XTestptr, FALSE); ActivateDevice(XTestkeybd, FALSE); flags[XTestptr->id] |= XISlaveAdded; flags[XTestkeybd->id] |= XISlaveAdded; if (c->enable) { EnableDevice(ptr, FALSE); EnableDevice(keybd, FALSE); flags[ptr->id] |= XIDeviceEnabled; flags[keybd->id] |= XIDeviceEnabled; EnableDevice(XTestptr, FALSE); EnableDevice(XTestkeybd, FALSE); flags[XTestptr->id] |= XIDeviceEnabled; flags[XTestkeybd->id] |= XIDeviceEnabled; } /* Attach the XTest virtual devices to the newly created master device */ AttachDevice(NULL, XTestptr, ptr); AttachDevice(NULL, XTestkeybd, keybd); flags[XTestptr->id] |= XISlaveAttached; flags[XTestkeybd->id] |= XISlaveAttached; unwind: free(name); return rc; }
/* Common function to either set the logging to a file or a file descriptor. */ static void set_file_fd (const char *name, int fd) { estream_t fp; int want_socket; #ifdef HAVE_W32CE_SYSTEM int use_writefile = 0; #endif struct fun_cookie_s *cookie; /* Close an open log stream. */ if (logstream) { es_fclose (logstream); logstream = NULL; } /* Figure out what kind of logging we want. */ if (name && !strcmp (name, "-")) { name = NULL; fd = es_fileno (es_stderr); } want_socket = 0; if (name && !strncmp (name, "tcp://", 6) && name[6]) want_socket = 1; #ifndef HAVE_W32_SYSTEM else if (name && !strncmp (name, "socket://", 9) && name[9]) want_socket = 2; #endif /*HAVE_W32_SYSTEM*/ #ifdef HAVE_W32CE_SYSTEM else if (name && !strcmp (name, "GPG2:")) { HANDLE hd; ActivateDevice (L"Drivers\\"GNUPG_NAME"_Log", 0); /* Ignore a filename and write the debug output to the GPG2: device. */ hd = CreateFile (L"GPG2:", GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); fd = (hd == INVALID_HANDLE_VALUE)? -1 : (int)hd; name = NULL; force_prefixes = 1; use_writefile = 1; } #endif /*HAVE_W32CE_SYSTEM*/ /* Setup a new stream. */ /* The xmalloc below is justified because we can expect that this function is called only during initialization and there is no easy way out of this error condition. */ cookie = xmalloc (sizeof *cookie + (name? strlen (name):0)); strcpy (cookie->name, name? name:""); cookie->quiet = 0; cookie->is_socket = 0; cookie->want_socket = want_socket; #ifdef HAVE_W32CE_SYSTEM cookie->use_writefile = use_writefile; #endif if (!name) cookie->fd = fd; else if (want_socket) cookie->fd = -1; else { do cookie->fd = open (name, O_WRONLY|O_APPEND|O_CREAT, (S_IRUSR|S_IRGRP|S_IROTH|S_IWUSR|S_IWGRP|S_IWOTH)); while (cookie->fd == -1 && errno == EINTR); } log_socket = cookie->fd; { es_cookie_io_functions_t io = { NULL }; io.func_write = fun_writer; io.func_close = fun_closer; fp = es_fopencookie (cookie, "w", io); } /* On error default to a stderr based estream. */ if (!fp) fp = es_stderr; es_setvbuf (fp, NULL, _IOLBF, 0); logstream = fp; /* We always need to print the prefix and the pid for socket mode, so that the server reading the socket can do something meaningful. */ force_prefixes = want_socket; missing_lf = 0; }
PIPELIB_API BOOL CreatePipe (PHANDLE hReadPipe, PHANDLE hWritePipe, LPSECURITY_ATTRIBUTES /* lpPipeAttributes */, DWORD /* nSize */) { int inst; WCHAR* wsKey; HANDLE h; *hReadPipe = NULL; *hWritePipe = NULL; for (inst = 0 ; inst < MAX_INSTANCES; inst++) { PrepareRegistryForInstance (inst, &wsKey); h = ActivateDevice (wsKey, 0); RegDeleteKey (HKEY_LOCAL_MACHINE, wsKey); free (wsKey); if (!h && GetLastError() != ERROR_DEVICE_IN_USE) { /* Something went wrong. Use GetLastError for extended information. */ return FALSE; } /* Although MSDN documents the error as INVALID_HANDLE_VALUE, I see it returning NULL here. */ if (h != INVALID_HANDLE_VALUE && h != NULL) break; } if (inst == MAX_INSTANCES) { SetLastError (ERROR_TOO_MANY_OPEN_FILES); return FALSE; } /* name + num + ':' + '\0' */ wchar_t device_name[(sizeof (NAME_BASE) - 1) + 2 + 1 + 1]; wsprintf (device_name, L"%s%02d:", NAME_BASE, inst); *hReadPipe = CreateFile (device_name, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); SetPipeName (*hReadPipe, device_name); *hWritePipe = CreateFile (device_name, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); return TRUE; }