Skip to content

Tutorial 04 06 Add Main Dispatcher Class

Matt Linder edited this page May 31, 2023 · 16 revisions

Harmony Core Logo

Tutorial 4: Add Main Dispatcher Class

In addition to adding dispatcher classes for all your individual traditional Synergy routines, you must add the generated master dispatcher class that is responsible for registering your routine dispatcher classes with the Traditional Bridge library code, enabling them to be dispatched to as needed.

This is what generic code for the master dispatcher class looks like, where <interface_name> is the name of the SMC interface with the definitions for the traditional Synergy routines you are exposing:

;;*****************************************************************************
;;
;; Title:       <interface_name>Dispatcher.dbl
;;
;; Description: Declares dispatcher classes for exposed methods
;;
;;*****************************************************************************

import Harmony.TraditionalBridge
import TraditionalBridge.Dispatchers.BridgeMethods

namespace TraditionalBridge.Dispatchers

    public partial class BridgeMethodsDispatcher extends RoutineDispatcher

        public method <interface_name>Dispatcher
        proc
            ;;Declare dispatcher classes for the '<interface_name>' interface methods
            mDispatchStubs.Add("<routine_name>", new <routine_name>_Dispatcher())
            InitHook()
        endmethod

    endclass

endnamespace

We recommend placing the master dispatcher class in the same folder and namespace as your routine dispatcher classes.

  1. In Solution Explorer, right-click the Dispatchers folder (TraditionalBridge > Sources > Dispatchers) and select Add > Existing Item from the context menu.

  2. In the Add Existing Item dialog, navigate to the Dispatchers folder, select BridgeMethodsDispatcher.dbl, and then click Add.

  3. Open the BridgeMethodsDispatcher.dbl file, which will look like this:

;;*****************************************************************************
;;
;; Title:       BridgeMethodsDispatcher.dbl
;;
;; Description: Declares dispatcher classes for exposed methods
;;
;;*****************************************************************************
;; WARNING: GENERATED CODE!
;; This file was generated by CodeGen. Avoid editing the file if possible.
;; Any changes you make will be lost if the file is re-generated.
;;*****************************************************************************

import Harmony.TraditionalBridge
import TraditionalBridge.Dispatchers.BridgeMethods

namespace TraditionalBridge.Dispatchers

    public partial class BridgeMethodsDispatcher extends RoutineDispatcher

        public method BridgeMethodsDispatcher
        proc
            ;;Declare dispatcher classes for the 'BridgeMethods' interface methods
            mDispatchStubs.Add("AddTwoNumbers", new AddTwoNumbers_Dispatcher())
            mDispatchStubs.Add("GetEnvironment", new GetEnvironment_Dispatcher())
            mDispatchStubs.Add("GetLogicalName", new GetLogicalName_Dispatcher())
            InitHook()
        endmethod
    endclass

endnamespace

Next topic: Add Traditional Bridge Host


Clone this wiki locally