mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-22 05:27:20 +00:00
[common] added back support for shared memory files
This commit is contained in:
parent
0dc0e6490c
commit
45ee79014d
@ -52,22 +52,6 @@ static struct Option options[] =
|
|||||||
.type = OPTION_TYPE_STRING,
|
.type = OPTION_TYPE_STRING,
|
||||||
.value.x_string = NULL,
|
.value.x_string = NULL,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
.module = "app",
|
|
||||||
.name = "shmFile",
|
|
||||||
.description = "The path to the shared memory file",
|
|
||||||
.shortopt = 'f',
|
|
||||||
.type = OPTION_TYPE_STRING,
|
|
||||||
.value.x_string = "/dev/shm/looking-glass",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.module = "app",
|
|
||||||
.name = "shmSize",
|
|
||||||
.description = "Specify the size in MB of the shared memory file (0 = detect)",
|
|
||||||
.shortopt = 'L',
|
|
||||||
.type = OPTION_TYPE_INT,
|
|
||||||
.value.x_int = 0,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
.module = "app",
|
.module = "app",
|
||||||
.name = "renderer",
|
.name = "renderer",
|
||||||
@ -387,8 +371,6 @@ bool config_load(int argc, char * argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
// setup the application params for the basic types
|
// setup the application params for the basic types
|
||||||
params.shmFile = option_get_string("app", "shmFile" );
|
|
||||||
params.shmSize = option_get_int ("app", "shmSize" ) * 1048576;
|
|
||||||
params.cursorPollInterval = option_get_int ("app", "cursorPollInterval");
|
params.cursorPollInterval = option_get_int ("app", "cursorPollInterval");
|
||||||
params.framePollInterval = option_get_int ("app", "framePollInterval" );
|
params.framePollInterval = option_get_int ("app", "framePollInterval" );
|
||||||
|
|
||||||
|
@ -93,8 +93,6 @@ struct AppParams
|
|||||||
bool center;
|
bool center;
|
||||||
int x, y;
|
int x, y;
|
||||||
unsigned int w, h;
|
unsigned int w, h;
|
||||||
const char * shmFile;
|
|
||||||
unsigned int shmSize;
|
|
||||||
unsigned int fpsLimit;
|
unsigned int fpsLimit;
|
||||||
bool showFPS;
|
bool showFPS;
|
||||||
bool useSpiceInput;
|
bool useSpiceInput;
|
||||||
|
@ -82,6 +82,18 @@ static char * uioGetName(const char * shmDevice)
|
|||||||
|
|
||||||
static bool ivshmemDeviceValidator(struct Option * opt, const char ** error)
|
static bool ivshmemDeviceValidator(struct Option * opt, const char ** error)
|
||||||
{
|
{
|
||||||
|
// if it's not a uio device, it must be a file on disk
|
||||||
|
if (strlen(opt->value.x_string) > 3 && memcmp(opt->value.x_string, "uio", 3) != 0)
|
||||||
|
{
|
||||||
|
struct stat st;
|
||||||
|
if (stat(opt->value.x_string, &st) != 0)
|
||||||
|
{
|
||||||
|
*error = "Invalid path to the ivshmem file specified";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
char * name = uioGetName(opt->value.x_string);
|
char * name = uioGetName(opt->value.x_string);
|
||||||
if (!name)
|
if (!name)
|
||||||
{
|
{
|
||||||
@ -133,11 +145,12 @@ void ivshmemOptionsInit()
|
|||||||
struct Option options[] =
|
struct Option options[] =
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
.module = "os",
|
.module = "app",
|
||||||
.name = "shmDevice",
|
.name = "shmFile",
|
||||||
.description = "The IVSHMEM device to use",
|
.shortopt = 'f',
|
||||||
|
.description = "The path to the shared memory file, or the name of the uio device to use, ie: uio0",
|
||||||
.type = OPTION_TYPE_STRING,
|
.type = OPTION_TYPE_STRING,
|
||||||
.value.x_string = "uio0",
|
.value.x_string = "/dev/shm/looking-glass",
|
||||||
.validator = ivshmemDeviceValidator,
|
.validator = ivshmemDeviceValidator,
|
||||||
.getValues = ivshmemDeviceGetValues
|
.getValues = ivshmemDeviceGetValues
|
||||||
},
|
},
|
||||||
@ -151,12 +164,15 @@ bool ivshmemOpen(struct IVSHMEM * dev)
|
|||||||
{
|
{
|
||||||
assert(dev);
|
assert(dev);
|
||||||
|
|
||||||
const char * shmDevice = option_get_string("os", "shmDevice");
|
const char * shmDevice = option_get_string("app", "shmFile");
|
||||||
unsigned int devSize;
|
unsigned int devSize;
|
||||||
int devFD;
|
int devFD;
|
||||||
|
|
||||||
|
dev->opaque = NULL;
|
||||||
|
|
||||||
DEBUG_INFO("KVMFR Device : %s", shmDevice);
|
DEBUG_INFO("KVMFR Device : %s", shmDevice);
|
||||||
|
|
||||||
|
if (strlen(shmDevice) > 3 && memcmp(shmDevice, "uio", 3) == 0)
|
||||||
{
|
{
|
||||||
// get the device size
|
// get the device size
|
||||||
int fd = uioOpenFile(shmDevice, "maps/map0/size");
|
int fd = uioOpenFile(shmDevice, "maps/map0/size");
|
||||||
@ -178,9 +194,7 @@ bool ivshmemOpen(struct IVSHMEM * dev)
|
|||||||
size[len] = '\0';
|
size[len] = '\0';
|
||||||
close(fd);
|
close(fd);
|
||||||
devSize = strtoul(size, NULL, 16);
|
devSize = strtoul(size, NULL, 16);
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
char * path;
|
char * path;
|
||||||
alloc_sprintf(&path, "/dev/%s", shmDevice);
|
alloc_sprintf(&path, "/dev/%s", shmDevice);
|
||||||
devFD = open(path, O_RDWR, (mode_t)0600);
|
devFD = open(path, O_RDWR, (mode_t)0600);
|
||||||
@ -193,11 +207,27 @@ bool ivshmemOpen(struct IVSHMEM * dev)
|
|||||||
}
|
}
|
||||||
free(path);
|
free(path);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
struct stat st;
|
||||||
|
if (stat(shmDevice, &st) != 0)
|
||||||
|
{
|
||||||
|
DEBUG_ERROR("Failed to stat: %s", shmDevice);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
devSize = st.st_size;
|
||||||
|
devFD = open(shmDevice, O_RDWR, (mode_t)0600);
|
||||||
|
if (devFD < 0)
|
||||||
|
{
|
||||||
|
DEBUG_ERROR("Failed to open: %s", shmDevice);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void * map = mmap(0, devSize, PROT_READ | PROT_WRITE, MAP_SHARED, devFD, 0);
|
void * map = mmap(0, devSize, PROT_READ | PROT_WRITE, MAP_SHARED, devFD, 0);
|
||||||
if (map == MAP_FAILED)
|
if (map == MAP_FAILED)
|
||||||
{
|
{
|
||||||
const char * shmDevice = option_get_string("os", "shmDevice");
|
|
||||||
DEBUG_ERROR("Failed to map the shared memory device: %s", shmDevice);
|
DEBUG_ERROR("Failed to map the shared memory device: %s", shmDevice);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -217,6 +247,9 @@ void ivshmemClose(struct IVSHMEM * dev)
|
|||||||
{
|
{
|
||||||
assert(dev);
|
assert(dev);
|
||||||
|
|
||||||
|
if (!dev->opaque)
|
||||||
|
return;
|
||||||
|
|
||||||
struct IVSHMEMInfo * info =
|
struct IVSHMEMInfo * info =
|
||||||
(struct IVSHMEMInfo *)dev->opaque;
|
(struct IVSHMEMInfo *)dev->opaque;
|
||||||
|
|
||||||
@ -224,4 +257,5 @@ void ivshmemClose(struct IVSHMEM * dev)
|
|||||||
close(info->fd);
|
close(info->fd);
|
||||||
|
|
||||||
free(info);
|
free(info);
|
||||||
|
dev->opaque = NULL;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user