Open Core Interface - MLPI
MLPI-MotionLogicProgrammingInterface(mlpi4Java)  1.26.2
MlpiConnection.java
Go to the documentation of this file.
1 // -----------------------------------------------------------------------
2 // MLPI - <MlpiConnection.java>
3 // -----------------------------------------------------------------------
4 // Copyright (c) 2012 Bosch Rexroth. All rights reserved.
5 // Redistribution and use in source and binary forms of this MLPI software
6 // (SW) provided to you, with or without modification, are permitted
7 // without prior approval provided that the following conditions are met:
8 //
9 // 1. Redistributions of source code of SW must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // 2. Redistributions in binary form of SW must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in the
14 // documentation and/or other materials provided with the distribution.
15 //
16 // 3. User recognizes and acknowledges that it acquires no right,
17 // title or interest in or to any of the names or trademarks used in
18 // connection with the SW ("names") by virtue of this License and waives
19 // any right to or interest in the names. User recognizes and acknowledges
20 // that names of companies or names or products of companies displayed
21 // in the documentation of SW to indicate the interoperability of products
22 // with the SW are the names of their respective owners. The use of such
23 // names in the documentation of SW does not imply any sponsorship,
24 // approval, or endorsement by such companies of this product.
25 //
26 // 4. Modified code versions, i.e. any addition to or deletion from
27 // the substance or structure of the original code of the SW running
28 // the MLPI must be plainly marked as such and must not be misrepresented
29 // as being original SW.
30 //
31 // 5. The SW may only be used in connection with a Bosch Rexroth product.
32 //
33 // THIS INFORMATION IS PROVIDED BY BOSCH REXROTH CORPORATION "AS IS"
34 // AND WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED, INCLUDING
35 // (BUT NOTLIMITED TO) ANY IMPLIED WARRANTIES OF MERCHANTABILITY,
36 // FITNESS FOR ANY PARTICULAR PURPOSE, OR NON-INFRINGEMENT. WHILE THE
37 // INFORMATION PROVIDED IS BELIEVED TO BE ACCURATE, IT MAY INCLUDE
38 // ERRORS OR INACCURACIES.
39 // SUBJECT TO COMPULSORY STATUTORY PROVISIONS OF THE GERMAN LAW AS
40 // THE APPLICABLE LAW FOR THIS LICENSE BOSCH REXROTH CORPORATION WILL
41 // NOT BE LIABLE FOR ANY DAMAGES OF ANY KIND ARISING FROM THE USE OF
42 // THE SOFTWARE DISTRIBUTED HEREUNDER, INCLUDING BUT NOT LIMITED TO
43 // DIRECT, INDIRECT, INCIDENTAL, PUNITIVE, AND CONSEQUENTIAL DAMAGES.
44 // -----------------------------------------------------------------------
45 //
55 //
56 // -----------------------------------------------------------------------
57 package com.boschrexroth.mlpi;
58 
66 public class MlpiConnection implements MlpiComponent.MlpiHandle {
67 
68  final static String[] libnames = {
69  "mlpijavawin64", // library with old name schema - windows DLL, 64 Bit
70  "mlpijavawin64d", // library with old name schema - windows DLL, 64 Bit
71  "mlpijavawin32", // library with old name schema - windows DLL, 32 Bit
72  "mlpijavawin32d", // library with old name schema - windows DLL, 32 Bit
73  "mlpijavaandroid", // library with old name schema - android so, 32 Bit
74  "mlpijava-linux-gcc-x64", // library with new name schema - linux gcc so, 64 Bit, x64
75  "mlpijava-linux-gcc-x86", // library with new name schema - linux gcc so, 32 Bit, x86
76  "mlpijava-linux-gcc-armhf", // library with new name schema - linux gcc so, 64 Bit, armhf
77  "mlpijava-linux-gcc-arm", // library with new name schema - linux gcc so, 32 Bit, arm
78  "mlpijava" // and the LAST ONE: default library name 'libmlpijava.*'
79  };
80 
81  final static String[] openssl_libnames = {
82  "libeay32", // in windows we have to load the ssl libraries before
83  "ssleay32", // we try to load the mlpi library because we have some dependencies
84  "crypto",
85  "ssl"
86  };
87 
88  static {
89  for(int i = 0; i < openssl_libnames.length - 1; i=i+2) {
90  try {
91  java.lang.System.out.print("Try to load OpenSSL library '" + openssl_libnames[i]);
92  java.lang.System.loadLibrary(openssl_libnames[i]);
93  java.lang.System.out.println("'... succeeded.");
94 
95  java.lang.System.out.print("Try to load OpenSSL library '" + openssl_libnames[i+1]);
96  java.lang.System.loadLibrary(openssl_libnames[i+1]);
97  java.lang.System.out.println("'... succeeded.");
98  break;
99  }
100  catch (UnsatisfiedLinkError e) {
101  java.lang.System.out.println("'... failed.");
102  }
103  }
104  }
105 
106  static {
107  boolean loaded = false;
108  for(String libname : libnames ) {
109  try {
110  java.lang.System.out.print("Try to load library '" + libname);
111  java.lang.System.loadLibrary(libname);
112  java.lang.System.out.println("'... succeeded.");
113  loaded = true;
114  break;
115  }
116  catch (UnsatisfiedLinkError e) {
117  java.lang.System.out.println("'... failed.");
118  }
119  }
120  if(loaded==false) {
121  throw new UnsatisfiedLinkError("Could not find valid MLPI JNI library.");
122  }
123  }
124 
125  /*
126  * Structs
127  */
144  public static class Version
145  {
146  public int major;
147  public int minor;
148  public int bugfix;
149  public int patch;
150  public int build;
151  }
152 
165  public static class ConnectionInfo
166  {
167  public double minimum;
168  public double maximum;
169  public double average;
170  public double variance;
171  public double standardDeviation;
172  }
173 
184  public enum ApiProtection
185  {
186  MLPI_API_PROTECTION_NON (0x00),
187  MLPI_API_PROTECTION_WATCHDOG (0x01),
188  MLPI_API_PROTECTION_COMPLETE (0x02);
189 
190  private int _code;
191  int getCode() { return _code; }
192  ApiProtection(int code) { this._code = code; }
193  static ApiProtection valueOf(int code) {
194  for (ApiProtection value : values()) {
195  if (code == value.getCode()) return value;
196  }
197  return null;
198  }
199  }
200 
218  public static class ConnectionDescription
219  {
220  public long uid;
221  public String user;
222  public String uri;
223  public String name;
224  public String label;
225  public MlpiGlobal.DateAndTime dateTime = new MlpiGlobal.DateAndTime();
226  public int requestCounter;
227  public int lastRequest;
228  public ApiProtection protection;
229  public int watchdog;
230  }
231 
241  public static class Library
242  {
243  public String name;
244  public long id;
245  }
246 
247  /*
248  * Fields
249  */
250  private long _connectionHandle = -1;
251  private Logic _logic = new Logic(this);
252  private System _system = new System(this);
253  private Watchdog _watchdog = new Watchdog(this);
254  private Motion _motion = new Motion(this);
255  private Io _io = new Io(this);
256  private Parameter _parameter = new Parameter(this);
257  private Robot _robot = new Robot(this);
258  private Container _container = new Container(this);
259  private Task _task = new Task(this);
260  private Security _security = new Security(this);
261  private AccessControl _accessControl = new AccessControl(this);
262 
263  /*
264  * Methods
265  */
268  public MlpiConnection() {
269  }
270 
273  public void finalize() {
274  disconnect();
275  }
276 
324  public void connect(String address) {
325  // don't forget to delete native connection object
326  if (getConnectionHandle() != -1) {
327  disconnect();
328  }
329 
330  try{
331  // call connection facility and create connection
332  long handle = connectInternal2(address);
333 
334  // update all slave objects of object model
335  if (handle != -1 && handle != 0) {
336  setConnectionHandle(handle);
337  } else {
338  throw new MlpiException("Internal error during MLPI connection!");
339  }
340  }
341  catch(UnsatisfiedLinkError e) {
342  throw new MlpiException("MLPI_E_FAIL: General error during function call. MLPI JNI library mismatch (old native shared library).");
343  }
344 
345  }
346 
354  public void disconnect() {
355  try{
356  // delete current connection
357  disconnectInternal2(getConnectionHandle());
358  }
359  catch(UnsatisfiedLinkError e) {
360  throw new MlpiException("MLPI_E_FAIL: General error during function call. MLPI JNI library mismatch (old native shared library).");
361  }
362 
363  // update all slave objects of object model
364  setConnectionHandle(-1);
365  }
366 
367  private native long connectInternal2(String address);
368  private native void disconnectInternal2(long handle);
369 
370  private void setConnectionHandle(long handle) {
371  _connectionHandle = handle;
372  }
373 
377  public long getConnectionHandle() {
378  return _connectionHandle;
379  }
380 
385  public Logic logic() {
386  return _logic;
387  }
388 
393  public System system() {
394  return _system;
395  }
396 
400  public Watchdog watchdog() {
401  return _watchdog;
402  }
403 
407  public Motion motion() {
408  return _motion;
409  }
410 
414  public Io io() {
415  return _io;
416  }
417 
421  public Parameter parameter() {
422  return _parameter;
423  }
424 
428  public Robot robot() {
429  return _robot;
430  }
431 
435  public Container container() {
436  return _container;
437  }
438 
442  public Task task() {
443  return _task;
444  }
445 
449  public Security security() {
450  return _security;
451  }
452 
456  @Deprecated
457  public Security Security() {
458  return _security;
459  }
460 
465  return _accessControl;
466  }
467 
471  @Deprecated
473  return _accessControl;
474  }
475 
487  public native boolean isConnected();
488 
501  public native Version getClientCoreVersion();
502 
515  public native Version getServerCoreVersion();
516 
531  public native void delay(int delayMilliseconds);
532 
556  public native ConnectionInfo testConnection(int payloadBytes, int numMeasurements);
557 
571  public native void setNameOfConnection(String name);
572 
586  public native void setLabelOfConnection(String label);
587 
611 
638 
648  public native void closeConnectionByUid(long uid);
649 
658  public native void closeConnectionsByUser(String user);
659 
668  public native void closeConnectionsByUri(String uri);
669 
677  public native void userAccountControlReload();
678 
686  public native void userAccountControlLoadAccounts(String path);
687 
695  public native void userAccountControlUnloadAccounts(String path);
696 
704  public native String[] getOwnPermissions();
705 
716  public native String[] getAccounts();
717 
727  public native String[] getAccountPermissions(String account);
728 
747  public native Library[] getLibrarySupport();
748 }
native void userAccountControlLoadAccounts(String path)
Empty class definition which defines global structures/classes.
Definition: MlpiGlobal.java:65
Class definition of the SystemLib.
Definition: System.java:65
Class definition of the TaskLib.
Definition: Task.java:67
native void userAccountControlUnloadAccounts(String path)
Class definition of the AccessControlLib.
Class definition of the mlpiRobotLib.
Definition: Robot.java:84
native void closeConnectionsByUri(String uri)
This structure is used by the function testConnection to return the results of the timing measurement...
Class definition of the LogicLib.
Definition: Logic.java:63
This enumeration defines the protection levels of a connection.
This class defines information about the date and time.
Class definition of the ParameterLib.
Definition: Parameter.java:70
native ConnectionDescription getOwnConnectionDescription()
This structure is used by getOwnConnectionDescription and getAllConnectionDescription to provide info...
native void delay(int delayMilliseconds)
Describes the API version information.
native ConnectionInfo testConnection(int payloadBytes, int numMeasurements)
native String[] getAccountPermissions(String account)
native void closeConnectionsByUser(String user)
native Library[] getLibrarySupport()
Class definition of the MotionLib.
Definition: Motion.java:66
native ConnectionDescription[] getAllConnectionDescription()
native void setNameOfConnection(String name)
native void closeConnectionByUid(long uid)
Class definition of the WatchdogLib.
Definition: Watchdog.java:70
Definition of the MlpiConnection which is the root object of a connection to a MLPI Device...
native void setLabelOfConnection(String label)
Class definition of the IoLib.
Definition: Io.java:65
This structure is used by getLibrarySupport to provide getting names and IDs of supported libraries...
Exception class for all MLPI runtime errors.