Opened 3 months ago

Closed 3 months ago

#2233 closed enhancement (fixed)

Change enumeration typemaps in SWIG Java

Reported by: nanang Owned by: nanang
Priority: normal Milestone: release-2.10
Component: pjsua2 Version: trunk
Keywords: Cc:
Backport to 1.x milestone: Backported: no

Description

Currently we use SWIG default typemap for enumeration, i.e: typesafe enums. But now we find that it may not be the best approach for PJSIP (see pro vs cons below). This ticket will change the typemap to type-unsafe enums.

Pro:

  • Some PJSIP C enumerations are actually not pure enumeration, for example PJSIP_TRANSPORT_IPV6 in pjsip_transport_type_e is actually a bitflag value.
  • After #2219, there is still crash reported that may be caused by enumeration.
  • Method swigToEnum() generated by SWIG for typesafe enum contains iteration which is not efficient on enumeration types whose big and non-contiguous values, e.g: pj_ssl_cert_verify_flag_t whose values ranging from 0 to (1<<31) with exponentially increased intervals.
  • Some PJSIP enumerations define only subset values, e.g: pj_ssl_cipher only defines some basic SSL/TLS ciphers, so any Java variable typed pj_ssl_cipher or function returning pj_ssl_cipher cannot contain or return non basic ciphers.

Cons:

  • Backward compatibility issue!

Changes to be done in application

As described above, this ticket introduces backward compatibility issues, here are modifications needed to be done in Java applications:

  • accessing enumeration value is no longer using swigValue() method, e.g: pjsip_inv_state.PJSIP_INV_STATE_CONFIRMED.swigValue() must be changed to pjsip_inv_state.PJSIP_INV_STATE_CONFIRMED.
  • all enumeration types are now int, e.g: pjsip_status_code code must be changed to int code

Change History (1)

comment:1 Changed 3 months ago by nanang

  • Owner set to nanang
  • Resolution set to fixed
  • Status changed from new to closed

In 6075:

Close #2233: Changed enumeration approach in SWIG Java to type-unsafe enums.

Note: See TracTickets for help on using tickets.