/* * bridge_context.prg - FiveNode Request Context (Harbour side) * JSON-based context access, output buffer wrappers * * Copyright (c) 2026 Charles KWON ( Charles KWON Ohjun, charleskwonohjun@gmail.com ) * All rights reserved. */ FUNCTION BRIDGE_SETUP_ERRORBLOCK() LOCAL nH := FCreate( hb_DirTemp() + "errblock_proof.txt" ) FWrite( nH, "ErrorBlock SET at " + Time() ) FClose( nH ) ErrorBlock( {| e | Break( e ) } ) RETURN NIL FUNCTION BRIDGE_PING() hb_MemoWrit( hb_DirTemp() + "ping_proof.txt", "PING_EXECUTED" ) _BRIDGE_SET_RESULT( "PONG" ) RETURN NIL FUNCTION hb_bridge_get_output() RETURN _OUT_GET() FUNCTION hb_bridge_clear_output() _OUT_CLEAR() RETURN NIL FUNCTION bridge_output_append( cText ) _OUT_APPEND( cText ) RETURN NIL // ── Context value accessor (extract from JSON via hb_jsonDecode) ── FUNCTION ctx_get( cKey, xDefault ) LOCAL cJson := _CTX_GET_JSON() LOCAL hCtx IF Empty( cJson ) RETURN xDefault ENDIF hb_jsonDecode( cJson, @hCtx ) IF ValType( hCtx ) == "H" .AND. hb_HHasKey( hCtx, cKey ) RETURN hCtx[ cKey ] ENDIF RETURN xDefault FUNCTION ctx_set( cKey, xValue ) LOCAL cJson := _CTX_GET_JSON() LOCAL hCtx IF Empty( cJson ) hCtx := { => } ELSE hb_jsonDecode( cJson, @hCtx ) IF ValType( hCtx ) != "H" hCtx := { => } ENDIF ENDIF hCtx[ cKey ] := xValue _CTX_SET_JSON( hb_jsonEncode( hCtx ) ) RETURN xValue