public void sendEvent(AbstractEvent event, int channel) {
   synchronized (inputQueues[channel]) {
     inputQueues[channel].add(InputValue.event(event));
     inputQueues[channel].notifyAll();
   }
   inputGate.onAvailableBuffer(inputChannels[channel].getInputChannel());
 }
 public void sendElement(Object element, int channel) {
   synchronized (inputQueues[channel]) {
     inputQueues[channel].add(InputValue.element(element));
     inputQueues[channel].notifyAll();
   }
   inputGate.onAvailableBuffer(inputChannels[channel].getInputChannel());
 }
  private boolean hasNoneOrOnlyExternalInput(
      final ProcessorGraphNode<Object, Object> node,
      final Set<InputValue> inputs,
      final Map<String, ProcessorGraphNode<Object, Object>> provideBy) {
    if (inputs.isEmpty()) {
      return true;
    }

    for (InputValue input : inputs) {
      final ProcessorGraphNode<Object, Object> provider = provideBy.get(input.getName());
      if (provider != null && provider != node) {
        return false;
      }
    }
    return true;
  }
 public void endInput() {
   for (int i = 0; i < numInputChannels; i++) {
     synchronized (inputQueues[i]) {
       inputQueues[i].add(InputValue.streamEnd());
       inputQueues[i].notifyAll();
     }
     inputGate.onAvailableBuffer(inputChannels[i].getInputChannel());
   }
 }
예제 #5
0
  @Override
  protected boolean handleTouchController(MotionEvent event) {

    int action = event.getAction();
    int actionEvent = action & MotionEvent.ACTION_MASK;

    int pid = 0;

    try {
      int pointerIndex =
          (event.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK)
              >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
      pid = event.getPointerId(pointerIndex);
    } catch (Error e) {
      pid = (action & MotionEvent.ACTION_POINTER_ID_SHIFT) >> MotionEvent.ACTION_POINTER_ID_SHIFT;
    }

    // dumpEvent(event);

    for (int i = 0; i < 10; i++) {
      touchstates[i] = false;
      oldtouches[i] = newtouches[i];
    }

    for (int i = 0; i < event.getPointerCount(); i++) {

      int actionPointerId = event.getPointerId(i);

      int x = (int) event.getX(i);
      int y = (int) event.getY(i);

      if (actionEvent == MotionEvent.ACTION_UP
          || (actionEvent == MotionEvent.ACTION_POINTER_UP && actionPointerId == pid)
          || actionEvent == MotionEvent.ACTION_CANCEL) {
        // nada
      } else {
        // int id = i;
        int id = actionPointerId;
        if (id > touchstates.length)
          continue; // strange but i have this error on my development console
        touchstates[id] = true;
        // newtouches[id] = 0;

        for (int j = 0; j < values.size(); j++) {
          InputValue iv = values.get(j);

          if (iv.getRect().contains(x, y)) {

            // Log.d("touch","HIT "+iv.getType()+" "+iv.getRect()+ " "+iv.getOrigRect());

            if (iv.getType() == TYPE_BUTTON_RECT || iv.getType() == TYPE_STICK_RECT) {

              switch (actionEvent) {
                case MotionEvent.ACTION_DOWN:
                case MotionEvent.ACTION_POINTER_DOWN:
                case MotionEvent.ACTION_MOVE:
                  if (iv.getType() == TYPE_BUTTON_RECT) {
                    newtouches[id] |= getButtonValue(iv.getValue(), true);
                    if (iv.getValue() == BTN_L2) {
                      if (!Emulator.isInMAME()) mm.showDialog(DialogHelper.DIALOG_EXIT);
                      else mm.showDialog(DialogHelper.DIALOG_EXIT_GAME);
                    } else if (iv.getValue() == BTN_R2) {
                      mm.showDialog(DialogHelper.DIALOG_OPTIONS);
                    }
                  } else if (mm.getPrefsHelper().getControllerType() == PrefsHelper.PREF_DIGITAL
                      && !(TiltSensor.isEnabled() && Emulator.isInMAME())) {
                    newtouches[id] = getStickValue(iv.getValue());
                  }

                  if (oldtouches[id] != newtouches[id]) pad_data[0] &= ~(oldtouches[id]);

                  pad_data[0] |= newtouches[id];
              }
              if (Emulator.getValue(Emulator.BPLUSX_KEY) == 1
                  && (iv.getValue() == BTN_B || iv.getValue() == BTN_X)) break;
            } /* else if (iv.getType() == TYPE_SWITCH) {
              	if (event.getAction() == MotionEvent.ACTION_DOWN) {

              		for (int ii = 0; ii < 10; ii++)
              		{
              		    touchstates[ii] = false;
              		    oldtouches[ii] = 0;
              		}
              		changeState();
              		mm.getMainHelper().updateMAME4all();
              		return true;
              	}
              }*/
          }
        }
      }
    }

    for (int i = 0; i < touchstates.length; i++) {
      if (!touchstates[i] && newtouches[i] != 0) {
        boolean really = true;

        for (int j = 0; j < 10 && really; j++) {
          if (j == i) continue;
          really = (newtouches[j] & newtouches[i]) == 0; // try to fix something buggy touch screens
        }

        if (really) {
          pad_data[0] &= ~(newtouches[i]);
        }

        newtouches[i] = 0;
        oldtouches[i] = 0;
      }
    }

    handleImageStates();

    Emulator.setPadData(0, pad_data[0]);
    return true;
  }
  /**
   * Create a {@link ProcessorDependencyGraph}.
   *
   * @param processors the processors that will be part of the graph
   * @return a {@link org.mapfish.print.processor.ProcessorDependencyGraph} constructed from the
   *     passed in processors
   */
  @SuppressWarnings("unchecked")
  public ProcessorDependencyGraph build(final List<? extends Processor> processors) {
    ProcessorDependencyGraph graph = new ProcessorDependencyGraph();

    final Map<String, ProcessorGraphNode<Object, Object>> provideBy =
        new HashMap<String, ProcessorGraphNode<Object, Object>>();
    final Map<String, Class<?>> outputTypes = new HashMap<String, Class<?>>();
    final List<ProcessorGraphNode<Object, Object>> nodes =
        new ArrayList<ProcessorGraphNode<Object, Object>>(processors.size());

    for (Processor<Object, Object> processor : processors) {
      final ProcessorGraphNode<Object, Object> node =
          new ProcessorGraphNode<Object, Object>(processor, this.metricRegistry);
      for (OutputValue value : getOutputValues(node)) {
        String outputName = value.getName();
        if (provideBy.containsKey(outputName)) {
          // there is already an output with the same name
          if (value.canBeRenamed()) {
            // if this is just a debug output, we can simply rename it
            outputName = outputName + "_" + UUID.randomUUID().toString();
          } else {
            throw new IllegalArgumentException(
                "Multiple processors provide the same output mapping: '"
                    + processor
                    + "' and '"
                    + provideBy.get(outputName)
                    + "' both provide: '"
                    + outputName
                    + "'.  You have to rename one of the outputs and the corresponding input so that"
                    + " there is no ambiguity with regards to the input a processor consumes.");
          }
        }

        provideBy.put(outputName, node);
        outputTypes.put(outputName, value.getType());
      }
      nodes.add(node);
    }

    ArrayList<ProcessorDependency> allDependencies = Lists.newArrayList(this.dependencies);
    for (ProcessorGraphNode<Object, Object> node : nodes) {
      if (node.getProcessor() instanceof CustomDependencies) {
        CustomDependencies custom = (CustomDependencies) node.getProcessor();
        allDependencies.addAll(custom.createDependencies(nodes));
      }
    }
    final SetMultimap<ProcessorGraphNode<Object, Object>, InputValue> inputsForNodes =
        cacheInputsForNodes(nodes);
    for (ProcessorGraphNode<Object, Object> node : nodes) {
      final Set<InputValue> inputs = inputsForNodes.get(node);

      // check explicit, external dependencies between nodes
      checkExternalDependencies(allDependencies, node, nodes);

      // check input/output value dependencies
      for (InputValue input : inputs) {
        final ProcessorGraphNode<Object, Object> solution = provideBy.get(input.getName());
        if (solution != null && solution != node) {
          // check that the provided output has the same type
          final Class<?> inputType = input.getType();
          final Class<?> outputType = outputTypes.get(input.getName());
          if (inputType.isAssignableFrom(outputType)) {
            solution.addDependency(node);
          } else {
            throw new IllegalArgumentException(
                "Type conflict: Processor '"
                    + solution.getName()
                    + "' provides an output with name '"
                    + input.getName()
                    + "' and of type '"
                    + outputType
                    + " ', while "
                    + "processor '"
                    + node.getName()
                    + "' expects an input of that name with type '"
                    + inputType
                    + "'! Please rename one of the attributes in the mappings of the processors.");
          }
        }
      }
    }

    // once all dependencies are discovered, select the root nodes
    for (ProcessorGraphNode<Object, Object> node : nodes) {
      // a root node is a node that has no requirements (that is no other node
      // should be executed before the node) and that has only external inputs
      if (!node.hasRequirements()
          && hasNoneOrOnlyExternalInput(node, inputsForNodes.get(node), provideBy)) {
        graph.addRoot(node);
      }
    }

    Assert.isTrue(
        graph.getAllProcessors().containsAll(processors),
        "'" + graph + "' does not contain all the processors: " + processors);

    return graph;
  }