From: Steve H. <fus...@nt...> - 2006-05-03 01:02:55
|
Miklos, The problem is in the fact that the function pointers in fuse_operations can only be set to point to *static* members of a C++ object, so in the case of the init function we would have something like: class c_t { static void *op_init(void) { } void set_fuse_ops() { struct fuse_operations fuse_ops = {.... op_init, ... }; } }; But op_init is static and hence it cannot get any information about the object pointer for the instance of c_t from which set_fuse_ops is being called. Hence I cannot define op_init such that it returns the object pointer. The only way I could see around this is if I can access struct fuse and set the user_data directly, as follows: class c_t { struct fuse* fuse_instance; void set_fuse_ops() { struct fuse_operations fuse_ops = {...}; fuse_instance = fuse_new(...); fuse_instance->user_data = this; } }; Then to get the object pointer I do: fuse_context *fc = fuse_get_context(); if (fc) return static_cast<c_t*>(fc->fuse->user_data); The only issue is that I have to modify struct fuse to make user_data visible. Is there any other way of doing this without having to expose hidden fields in struct fuse? Thanks, Steve Miklos Szeredi wrote: >>The reason for this request is that I want to associate each fuse >>instance with a c++ object, such that I can have access to methods in >>the c++ object from within the statically FUSE file operation functions. >>The way I have done this is to set the fuse.user_data field to the >>object self pointer, and then I can access that pointer from within the >>static functions. This works fine except that I have to explicitly >>modify fuse.h so that the contents of the fuse structure are exposed in >>fuse.h. Is there any way of incorporating this so I don't have to modify >> fuse.h? > > > Yes: > > - return object pointer from init() method. > > - retreive object pointer with 'fuse_get_context()->private_data' > > Miklos > |