<commit_before>platform = require '../platform'

class BaseRuntime extends platform.EventEmitter
  constructor: (@definition) ->
    @definition.capabilities = [] unless definition.capabilities
    @graph = null

  setMain: (@graph) ->

  getType: -> @definition.protocol
  getAddress: -> @definition.address

  canDo: (capability) ->
    @definition.capabilities.indexOf(capability) isnt -1

  isConnected: -> false

  # Connect to the target runtime environment (iframe URL, WebSocket address)
  connect: ->

  disconnect: ->

  reconnect: ->
    do @disconnect
    do @connect

  # Start a NoFlo Network
  start: ->
    unless @graph
      throw new Error 'No graph defined for execution'
    @sendNetwork 'start',
      graph: @graph.name or @graph.properties.id

  # Stop a NoFlo network
  stop: ->
    unless @graph
      throw new Error 'No graph defined for execution'
    @sendNetwork 'stop',
      graph: @graph.name or @graph.properties.id

  # Set the parent element that some runtime types need
  setParentElement: (parent) ->

  # Get a DOM element rendered by the runtime for preview purposes
  getElement: ->

  recvRuntime: (command, payload) ->
    if command is 'runtime'
      for key, val of payload
        @definition[key] = val
      @emit 'capabilities', payload.capabilities or []
    @emit 'runtime',
      command: command
      payload: payload

  recvComponent: (command, payload) ->
    switch command
      when 'error'
        @emit 'network',
          command: command
          payload: payload
      else
        @emit 'component',
          command: command
          payload: payload

  recvGraph: (command, payload) ->
    @emit 'graph',
      command: command
      payload: payload

  recvNetwork: (command, payload) ->
    switch command
      when 'started'
        @emit 'execution',
          running: true
          label: 'running'
      when 'stopped'
        @emit 'execution',
          running: false
          label: 'stopped'
      when 'status'
        @emit 'execution',
          running: payload.running
          label: if payload.running then 'running' else 'stopped'
      when 'icon'
        @emit 'icon', payload
      else
        @emit 'network',
          command: command
          payload: payload

  sendRuntime: (command, payload) ->
    @send 'runtime', command, payload
  sendGraph: (command, payload) ->
    @send 'graph', command, payload
  sendNetwork: (command, payload) ->
    @send 'network', command, payload
  sendComponent: (command, payload) ->
    @send 'component', command, payload

  send: (protocol, command, payload) ->

module.exports = BaseRuntime
<commit_msg>Forward started+running from protocol instead of label<commit_after>platform = require '../platform'

class BaseRuntime extends platform.EventEmitter
  constructor: (@definition) ->
    @definition.capabilities = [] unless definition.capabilities
    @graph = null

  setMain: (@graph) ->

  getType: -> @definition.protocol
  getAddress: -> @definition.address

  canDo: (capability) ->
    @definition.capabilities.indexOf(capability) isnt -1

  isConnected: -> false

  # Connect to the target runtime environment (iframe URL, WebSocket address)
  connect: ->

  disconnect: ->

  reconnect: ->
    do @disconnect
    do @connect

  # Start a NoFlo Network
  start: ->
    unless @graph
      throw new Error 'No graph defined for execution'
    @sendNetwork 'start',
      graph: @graph.name or @graph.properties.id

  # Stop a NoFlo network
  stop: ->
    unless @graph
      throw new Error 'No graph defined for execution'
    @sendNetwork 'stop',
      graph: @graph.name or @graph.properties.id

  # Set the parent element that some runtime types need
  setParentElement: (parent) ->

  # Get a DOM element rendered by the runtime for preview purposes
  getElement: ->

  recvRuntime: (command, payload) ->
    if command is 'runtime'
      for key, val of payload
        @definition[key] = val
      @emit 'capabilities', payload.capabilities or []
    @emit 'runtime',
      command: command
      payload: payload

  recvComponent: (command, payload) ->
    switch command
      when 'error'
        @emit 'network',
          command: command
          payload: payload
      else
        @emit 'component',
          command: command
          payload: payload

  recvGraph: (command, payload) ->
    @emit 'graph',
      command: command
      payload: payload

  recvNetwork: (command, payload) ->
    switch command
      when 'started'
        @emit 'execution',
          running: if payload? and payload.running? then payload.running else true
          started: if payload? and payload.started then payload.started else true
      when 'stopped'
        @emit 'execution',
          running: if payload? and payload.running? then payload.running else false
          started: if payload? and payload.started then payload.started else false
      when 'status'
        @emit 'execution',
          running: payload.running
          started: payload.started
      when 'icon'
        @emit 'icon', payload
      else
        @emit 'network',
          command: command
          payload: payload

  sendRuntime: (command, payload) ->
    @send 'runtime', command, payload
  sendGraph: (command, payload) ->
    @send 'graph', command, payload
  sendNetwork: (command, payload) ->
    @send 'network', command, payload
  sendComponent: (command, payload) ->
    @send 'component', command, payload

  send: (protocol, command, payload) ->

module.exports = BaseRuntime

{'fraction_non_alphanumeric': 0.10092074381657339, 'fraction_numerical': 0.0003610760064993681, 'mean_word_length': 2.602080624187256, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '206230', 'n_tokens_mistral': 1515, 'n_tokens_neox': 1457, 'n_words': 513}