~ubuntu-branches/ubuntu/precise/jcsp/precise

« back to all changes in this revision

Viewing changes to src/jcsp-demos/doc-ex/jcsp/awt/FlasherNetworkSSD.java

  • Committer: Bazaar Package Importer
  • Author(s): Miguel Landaeta
  • Date: 2010-06-20 18:12:26 UTC
  • Revision ID: james.westby@ubuntu.com-20100620181226-8yg8d9rjjjiuy7oz
Tags: upstream-1.1-rc4
ImportĀ upstreamĀ versionĀ 1.1-rc4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
    //////////////////////////////////////////////////////////////////////
 
3
    //                                                                  //
 
4
    //  JCSP ("CSP for Java") Libraries                                 //
 
5
    //  Copyright (C) 1996-2008 Peter Welch and Paul Austin.            //
 
6
    //                2001-2004 Quickstone Technologies Limited.        //
 
7
    //                                                                  //
 
8
    //  This library is free software; you can redistribute it and/or   //
 
9
    //  modify it under the terms of the GNU Lesser General Public      //
 
10
    //  License as published by the Free Software Foundation; either    //
 
11
    //  version 2.1 of the License, or (at your option) any later       //
 
12
    //  version.                                                        //
 
13
    //                                                                  //
 
14
    //  This library is distributed in the hope that it will be         //
 
15
    //  useful, but WITHOUT ANY WARRANTY; without even the implied      //
 
16
    //  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR         //
 
17
    //  PURPOSE. See the GNU Lesser General Public License for more     //
 
18
    //  details.                                                        //
 
19
    //                                                                  //
 
20
    //  You should have received a copy of the GNU Lesser General       //
 
21
    //  Public License along with this library; if not, write to the    //
 
22
    //  Free Software Foundation, Inc., 59 Temple Place, Suite 330,     //
 
23
    //  Boston, MA 02111-1307, USA.                                     //
 
24
    //                                                                  //
 
25
    //  Author contact: P.H.Welch@kent.ac.uk                             //
 
26
    //                                                                  //
 
27
    //////////////////////////////////////////////////////////////////////
 
28
 
 
29
 
 
30
import org.jcsp.lang.*;
 
31
import org.jcsp.awt.*;
 
32
 
 
33
public class FlasherNetworkSSD implements CSProcess {
 
34
 
 
35
  final private long period;
 
36
  final private ActiveApplet activeApplet;
 
37
 
 
38
  public FlasherNetworkSSD (final long period,
 
39
                            final ActiveApplet activeApplet) {
 
40
    this.period = period;
 
41
    this.activeApplet = activeApplet;
 
42
  }
 
43
    
 
44
  public void run () {
 
45
 
 
46
    final One2OneChannel mouseEvent = Channel.one2one ();
 
47
    final One2OneChannel appletConfigure = Channel.one2one ();
 
48
    final One2OneChannelInt stopStart = Channel.one2oneInt ();
 
49
    final One2OneChannelInt destroy = Channel.one2oneInt ();
 
50
    final One2OneChannelInt destroyAck = Channel.one2oneInt ();
 
51
 
 
52
    activeApplet.addMouseEventChannel (mouseEvent.out());
 
53
    activeApplet.setConfigureChannel (appletConfigure.in());
 
54
    activeApplet.setStopStartChannel (stopStart.out());
 
55
    activeApplet.setDestroyChannels (destroy.out(), destroyAck.in());
 
56
    // activeApplet.setDestroyChannels (destroy.out(), destroyAck.in(), -1);
 
57
 
 
58
    new Parallel (
 
59
      new CSProcess[] {
 
60
        activeApplet,
 
61
        new FlasherControl (period, mouseEvent.in(), appletConfigure.out()),
 
62
        new CSProcess () {
 
63
          public void run () {
 
64
            while (true) {
 
65
              switch (stopStart.in().read ()) {
 
66
                case ActiveApplet.STOP:
 
67
                  System.out.println ("FlasherNetworkSSD: ActiveApplet.STOP received");
 
68
                break;
 
69
                case ActiveApplet.START:
 
70
                  System.out.println ("FlasherNetworkSSD: ActiveApplet.START received");
 
71
                break;
 
72
                default:
 
73
                  System.out.println ("FlasherNetworkSSD: ActiveApplet.<not STOP/START> received");
 
74
                break;
 
75
              }
 
76
            }
 
77
          }
 
78
        },
 
79
        new CSProcess () {
 
80
          public void run () {
 
81
            while (true) {
 
82
              switch (destroy.in().read ()) {
 
83
                case ActiveApplet.DESTROY:
 
84
                  System.out.println ("FlasherNetworkSSD: ActiveApplet.DESTROY received");
 
85
                  destroyAck.out().write (0);
 
86
                break;
 
87
                default:
 
88
                  System.out.println ("FlasherNetworkSSD: ActiveApplet.<not DESTROY> received");
 
89
                break;
 
90
              }
 
91
            }
 
92
          }
 
93
        }
 
94
      }
 
95
    ).run ();
 
96
 
 
97
  }
 
98
 
 
99
}