3 import java
.sql
.ResultSet
;
6 /** Generic base class for assigning mote usage privileges.
8 * This is an abstract class with the generic code to assign mote usage privileges.
9 * To integrate any custom reservation system, this class must be inherited and the
10 * abstract methods implemented.
13 public abstract class AbstractMoteAccess
{
15 /** Acquire mote control privileges using specific session.
17 * @param mote_ids IDs of mote to control.
18 * @param session_id ID of session that wants privileges.
19 * @return A boolean array with entries for each requested mote.
22 public boolean[] getMoteControlPrivileges(long[] mote_ids
, String session_id
) throws Exception
24 boolean[] results
= new boolean[mote_ids
.length
];
26 for (int i
= 0; i
< mote_ids
.length
; i
++) {
27 results
[i
] = getMoteControlPrivilege(mote_ids
[i
], session_id
);
33 /** Acquire control privilege for one mote.
35 * @param mote_id ID of mote to control.
36 * @param session_id ID of session that wants control privilege.
37 * @return True if mote control privilege was granted.
40 protected boolean getMoteControlPrivilege(long mote_id
, String session_id
) throws Exception
42 boolean access
= false;
46 // Check for current privileged session
47 String query
= "select priv_session_id from mote " +
49 sql
= new SQLHelper();
51 ResultSet sqlres
= sql
.retrieve(query
);
53 String privsess
= sqlres
.getString("priv_session_id");
54 if (privsess
== null || privsess
.compareTo(session_id
) == 0) {
57 // check privileges with reservation system
58 if (hasReservation(mote_id
,session_id
))
65 query
= "update mote set priv_session_id="+session_id
+
76 /** Check if session can reserve a given mote.
78 * This method must be implemented to integrate a custom
79 * reservation system. It is also a point for integration
80 * between user account system and reservation system.
82 * Note that the user model should specify the relevant
83 * reservation key upon session authentication. The details of
84 * how to do this are application specific.
86 * @param mote_id Database key for the mote to check
87 * @param session_id Database key for the session requesting access.
88 * @return True if there is a current reservation, false otherwise
91 abstract protected boolean hasReservation(long mote_id
, String session_id
) throws Exception
;