Skip to content

Tutorial 04 06 Add Main Dispatcher Class

mattl91 edited this page Nov 3, 2022 · 16 revisions

Harmony Core Logo

Tutorial 4: Add Main Dispatcher Class

Having created dispatcher classes for all of your individual traditional Synergy routines, you must create a 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 the generic code for the master dispatcher class looks like:

;;*****************************************************************************
;;
;; Title:       MethodDispatcher.dbl
;;
;; Description: Declares dispatcher classes for exposed methods
;;
;;*****************************************************************************

import Harmony.TraditionalBridge

namespace TraditionalBridge.Dispatchers

    public partial class MethodDispatcher extends RoutineDispatcher

        public method MethodDispatcher
        proc
            ;;Register routine dispatcher classes 
       
        endmethod

    endclass

endnamespace

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

  1. Right-click on the Dispatchers folder, select Add > Class, and name the new file MethodDispatcher.dbl.

  2. Replace the current code in the file with the sample scaffolding code shown above.

All that remains is to add a line of code to register all of your individual routine dispatcher classes with the environment.

  1. Add the following code to the body of the MethodDispatcher constructor method:

    mDispatchStubs.Add("AddTwoNumbers",  new AddTwoNumbersDispatcher())
    mDispatchStubs.Add("GetEnvironment", new GetEnvironmentDispatcher())
    mDispatchStubs.Add("GetLogicalName", new GetLogicalNameDispatcher())
    
  2. Save the file

Your master dispatcher class should now look like this:

;;*****************************************************************************
;;
;; Title:       MethodDispatcher.dbl
;;
;; Description: Declares dispatcher classes for exposed methods
;;
;;*****************************************************************************

import Harmony.TraditionalBridge

namespace TraditionalBridge.Dispatchers

	public partial class MethodDispatcher extends RoutineDispatcher

		public method MethodDispatcher
		proc
			;;Register routine dispatcher classes 
			mDispatchStubs.Add("AddTwoNumbers",  new AddTwoNumbersDispatcher())
			mDispatchStubs.Add("GetEnvironment", new GetEnvironmentDispatcher())
			mDispatchStubs.Add("GetLogicalName", new GetLogicalNameDispatcher())
       
		endmethod

	endclass

endnamespace

Build the Code

Before we move on, let's make sure the project builds:

  1. Right-click on the TraditionalBridge project and select Build.

  2. Check the Output window and verify that the build was successful.

    1>------ Build started: Project: TraditionalBridge, Configuration: Debug x64 ------
    ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
    

Next topic: Add Traditional Bridge Host


Clone this wiki locally