5 require_once 'plc_functions.php';
7 drupal_set_html_head('<link href="/planetlab/css/plc_peers.css" rel="stylesheet" type="text/css"/>');
9 // all known peers hashed on peer_id
13 function Peers ($api) {
15 // fake entry fot the local myplc
16 $local_fake_peer = array ('peername' => PLC_NAME,
17 'shortname' => PLC_SHORTNAME,
19 $hash['local']=$local_fake_peer;
21 $peer_columns=array('peer_id','shortname','peername');
23 $peers = $api->GetPeers($peer_filter,$peer_columns);
24 if ($peers) foreach ($peers as $peer) {
25 $hash[$peer['peer_id']]=$peer;
30 public static function is_local ($peer) {
31 return $peer['peer_id'] == 'local';
34 function peer ($peer_id) {
35 // use the fake local entry
38 return $this->hash[$peer_id];
41 public function peername ($peer_id) {
42 $peer = $this->peer ($peer_id);
43 return $peer['peername'];
46 public function shortname ($peer_id) {
47 $peer = $this->peer ($peer_id);
48 return $peer['shortname'];
51 public function label ($peer_id) {
52 $peer = $this->peer ($peer_id);
53 $result = $peer['peername'] . " (" . $peer['shortname'] . ")";
54 if (Peers::is_local ($peer))
55 $result = "[local] " . $result;
59 public function link ($peer_id,$text) {
61 return href("/",$text);
62 $peer = $this->peer ($peer_id);
63 return l_peer_t($peer['peer_id'],$text);
66 public function peer_link ($peer_id) {
68 return href("/",$this->label($peer_id));
69 $peer = $this->peer ($peer_id);
70 return l_peer_t($peer['peer_id'],$this->label($peer_id));
73 function classname ($peer_id) {
74 $shortname=strtolower($this->shortname($peer_id));
75 return "peer-$shortname";
78 function block_start ($peer_id) {
79 // start a <div> element with 2 classes:
80 // (1) generic: is either peer-local or peer-foreign
81 // (2) specific: is peer-<shortname> based on the plc's shortname
82 // e.g. at PLE we'd get <div class='peer-local peer-ple'>
83 // or <div class='peer-local peer-plc'>
84 // see plc_styles.css for how to have the more specific ones override the generic one
86 $generic='peer-local';
88 $generic='peer-foreign';
89 $specific=$this->classname($peer_id);
90 // add nifty-big for the rounded corner
91 printf ("<div class='$generic $specific nifty-big'>");
94 function block_end ($peer_id) {
98 // writes a cell in the table with the peer's shortname, link to the peer page,
99 // and classname set for proper color
100 function cell ($table, $peer_id) {
101 $table->cell ($this->link($peer_id,$shortname),
102 array('class'=>$this->classname($peer_id)));
107 ////////////////////////////////////////////////////////////
112 function PeerScope ($api, $peerscope) {
113 switch ($peerscope) {
115 $this->filter=array();
116 $this->label="all peers";
119 $this->filter=array("peer_id"=>NULL);
120 $this->label=PLC_SHORTNAME;
123 $this->filter=array("~peer_id"=>NULL);
124 $this->label="foreign peers";
127 if (my_is_int ($peerscope)) {
128 $peer_id=intval($peerscope);
129 $peers=$api->GetPeers(array("peer_id"=>$peer_id));
131 $peers=$api->GetPeers(array("shortname"=>$peerscope));
135 $peer_id=$peer['peer_id'];
136 $this->filter=array("peer_id"=>$peer_id);
137 $this->label='peer "' . $peer['shortname'] . '"';
139 $this->filter=array();
140 $this->label="[no such peerscope " . $peerscope . "]";
146 public function filter() {
147 return $this->filter;
149 public function label() {