Files
adam-acs/app/services/cwmp/immediate_command_state_machine.ts
T
Kevin L'HereecandCopilot d1c65dbf1e chore: initial commit — AdonisJS v7 TR-069 ACS
- Docker infrastructure (Dockerfile, docker-compose.yml, genieacs-sim)
- AdonisJS v7 app with Inertia.js + Vue 3
- MongoDB integration
- CWMP/TR-069 state machine engine
- Configuration engine with compliance tracking
- Branding: ADAM ACS (favicon, navbar, locales)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-29 16:46:37 +02:00

65 lines
1.8 KiB
TypeScript

import { Device } from '../../domain/device/device.js'
import { CWMPTaskQueue } from './task_queue.js'
import { DeviceActionExecutor } from './device_action_executor.js'
import { ExecutingCommandsState, DeviceContext, DeviceStateResult } from './main_state_machine.js'
import logger from '@adonisjs/core/services/logger'
/**
* State machine for "6 CONNECTION REQUEST" events.
* Only executes pending Immediate (I) commands - does NOT include NI commands.
*/
export class ImmediateCommandStateMachine {
private currentState: ExecutingCommandsState
private context: DeviceContext
constructor(device: Device, session: string, taskQueue: CWMPTaskQueue) {
// includeNI = false: only execute Immediate commands
this.currentState = new ExecutingCommandsState(false)
this.context = {
device,
session,
taskQueue,
services: {
deviceAction: new DeviceActionExecutor(taskQueue),
},
}
}
async start(): Promise<string> {
logger.info(`Starting immediate-command state machine for device ${this.context.device.deviceId?.serialNumber}`)
return this.execute()
}
async handleResponse(success: boolean, message: any): Promise<string> {
this.context.message = { success, data: message }
return this.execute()
}
getCurrentStateName(): string {
return this.currentState.name
}
isCompleted(): boolean {
return this.currentState.name === 'completed'
}
private async execute(): Promise<string> {
try {
const result: DeviceStateResult = await this.currentState.handle(this.context)
if (result.isComplete) {
return ''
}
if (result.response && result.response !== '') {
return result.response
}
return ''
} catch (error) {
logger.error(`Immediate-command state machine error: ${error}`)
return ''
}
}
}