Object Manager
Overview
The Object Manager provides handle-based object management for the FreeWorld OS. It manages file handles, directory handles, pipes, events, mutexes, and other kernel objects, similar to Windows' object manager.
Features
- Handle Management: Unique handle generation and tracking
- File Operations: Complete file read/write with filesystem integration
- File Pointer Management: Seek operations and file size queries
- Directory Objects: Directory handle management
- Pipe Objects: Named pipes with read/write operations
- Event Objects: Event synchronization (set/reset/wait)
- Mutex Objects: Mutual exclusion locks
- Access Control: Access mode and share mode checking
- Conflict Detection: Share mode conflict detection
Object Types
1. File Objects
File objects represent open files with read/write capabilities:
- Access Modes: GENERIC_READ, GENERIC_WRITE, GENERIC_EXECUTE, GENERIC_ALL
- Share Modes: FILE_SHARE_READ, FILE_SHARE_WRITE, FILE_SHARE_DELETE, FILE_SHARE_NONE
- Creation Dispositions: CREATE_NEW, CREATE_ALWAYS, OPEN_EXISTING, OPEN_ALWAYS, TRUNCATE_EXISTING
- File Pointer: Tracks current read/write position
Key Functions
createFile(path, accessMode, shareMode, creationDisposition)- Create/open file handlereadFile(handle, buffer, bytesToRead)- Read data from filewriteFile(handle, buffer, bytesToWrite)- Write data to filesetFilePointer(handle, distance, moveMethod)- Move file pointergetFileSize(handle)- Get file size
2. Directory Objects
Directory objects represent open directories:
createDirectory(path)- Create directory handle
3. Pipe Objects
Named pipes for inter-process communication:
createPipe(name, mode)- Create named pipereadPipe(handle, buffer, bytesToRead)- Read from pipewritePipe(handle, buffer, bytesToWrite)- Write to pipe
4. Event Objects
Event objects for synchronization:
createEvent(name, initialState, manualReset)- Create eventsetEvent(handle)- Set event to signaled stateresetEvent(handle)- Reset event to non-signaled state
5. Mutex Objects
Mutex objects for mutual exclusion:
createMutex(name, initialOwner)- Create mutexreleaseMutex(handle)- Release mutex ownership
Handle Management
The Object Manager generates unique handles for all objects:
createHandle(object)- Create handle for objectgetObject(handle)- Get object from handlecloseHandle(handle)- Close handle and cleanup objectfindHandlesForFile(filePath)- Find all handles for a filegetObjectTypeName(handle)- Get object type namegetAllHandles()- Get all active handlesgetHandleCount()- Get total handle count
Access Control
The Object Manager enforces access control:
checkAccess(handle, requiredAccess)- Check if handle has required accesscheckShareConflict(file1, file2)- Check for share mode conflicts
Integration
The Object Manager integrates with:
- Filesystem: Uses Node.js
fsmodule for file operations - Error Manager: Returns error codes for failed operations
- Process Management: Tracks handles per process
Usage Example
const ObjectManager = require('./system/object-manager');
const objMgr = new ObjectManager();
// Open file for reading
const handle = objMgr.createFile(
'/path/to/file.txt',
ObjectManager.ACCESS_MODE.GENERIC_READ,
ObjectManager.SHARE_MODE.FILE_SHARE_READ,
ObjectManager.CREATION_DISPOSITION.OPEN_EXISTING
);
// Read file
const buffer = Buffer.alloc(1024);
const result = objMgr.readFile(handle, buffer, 1024);
if (result.success) {
console.log(`Read ${result.bytesRead} bytes`);
}
// Close handle
objMgr.closeHandle(handle);