Search in sources :

Example 1 with OtpErlangPid

use of com.ericsson.otp.erlang.OtpErlangPid in project erlide_eclipse by erlang.

the class ProcessListView method makeActions.

private void makeActions() {
    refreshAction = new Action() {

        @Override
        public void run() {
            viewer.refresh();
        }
    };
    refreshAction.setText("Refresh");
    refreshAction.setToolTipText("Refresh process list");
    refreshAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
    doubleClickAction = new Action() {

        @Override
        public void run() {
            final ISelection selection = viewer.getSelection();
            final Object obj = ((IStructuredSelection) selection).getFirstElement();
            if (obj == null) {
                return;
            }
            final OtpErlangPid pid = (OtpErlangPid) ((OtpErlangTuple) obj).elementAt(0);
            final OtpErlangObject r = ErlangEngine.getInstance().getProclistService().getProcessInfo(getBackend().getOtpRpc(), pid);
            if (r instanceof OtpErlangList) {
                final OtpErlangList l = (OtpErlangList) r;
                final StringBuilder s = new StringBuilder();
                for (int i = 0; i < l.arity(); i++) {
                    final OtpErlangTuple e = (OtpErlangTuple) l.elementAt(i);
                    s.append(' ').append(e.elementAt(0).toString()).append("\t= ").append(e.elementAt(1).toString()).append('\n');
                }
                showMessage(s.toString());
            } else {
                showMessage("Process " + pid.toString() + " is probably dead.\nPlease refresh process list.");
            }
        }
    };
}
Also used : Action(org.eclipse.jface.action.Action) OtpErlangPid(com.ericsson.otp.erlang.OtpErlangPid) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) ISelection(org.eclipse.jface.viewers.ISelection) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple)

Example 2 with OtpErlangPid

use of com.ericsson.otp.erlang.OtpErlangPid in project erlide_eclipse by erlang.

the class TypeConverter method java2erlang.

@SuppressWarnings("boxing")
public static OtpErlangObject java2erlang(final Object obj, final Signature type) throws SignatureException {
    if (type.kind == 'x') {
        return TypeConverter.java2erlang(obj);
    }
    if (obj instanceof String) {
        return TypeConverter.cvtString(obj, type);
    }
    if (obj instanceof Character) {
        if (type.kind == 'i') {
            return new OtpErlangChar((Character) obj);
        }
        TypeConverter.failConversion(obj, type);
    }
    if (obj instanceof Number) {
        return TypeConverter.cvtNumber(obj, type);
    }
    if (obj instanceof Boolean) {
        if (type.kind == 'o') {
            return new OtpErlangAtom((Boolean) obj ? "true" : "false");
        }
        TypeConverter.failConversion(obj, type);
    }
    if (obj instanceof Collection<?>) {
        if (type.kind == 'l') {
            final Object[] v = ((Collection<?>) obj).toArray(new Object[] {});
            final OtpErlangObject[] vv = new OtpErlangObject[v.length];
            for (int i = 0; i < v.length; i++) {
                vv[i] = TypeConverter.java2erlang(v[i], type.content[0]);
            }
            return new OtpErlangList(vv);
        }
        TypeConverter.failConversion(obj, type);
    }
    if (obj instanceof Map<?, ?>) {
        if (type.kind == 'm') {
            @SuppressWarnings("unchecked") final Map<OtpErlangObject, OtpErlangObject> map = (Map<OtpErlangObject, OtpErlangObject>) obj;
            final int size = map.keySet().size();
            final OtpErlangObject[] keys = map.keySet().toArray(new OtpErlangObject[size]);
            final OtpErlangObject[] values = new OtpErlangObject[size];
            for (int i = 0; i < size; i++) {
                values[i] = map.get(keys[i]);
            }
            return new OtpErlangMap(keys, values);
        }
        TypeConverter.failConversion(obj, type);
    }
    if (obj instanceof OtpErlangPid) {
        return (OtpErlangPid) obj;
    }
    if (obj instanceof OtpErlangRef) {
        return (OtpErlangObject) obj;
    }
    if (obj instanceof OtpErlangBinary) {
        return (OtpErlangObject) obj;
    }
    if (obj instanceof OtpErlangObject) {
        TypeConverter.checkConversion(obj);
        return (OtpErlangObject) obj;
    }
    if (obj instanceof IConvertible) {
        return ((IConvertible) obj).toErlangObject();
    }
    if (obj != null && obj.getClass().isArray()) {
        final int len = Array.getLength(obj);
        // Class<?> component = obj.getClass().getComponentType();
        if (type.kind == 'b') {
            // TODO we can convert more things to binaries
            return new OtpErlangBinary(obj);
        }
        if (type.kind == 'l') {
            final OtpErlangObject[] vv = new OtpErlangObject[len];
            for (int i = 0; i < len; i++) {
                vv[i] = TypeConverter.java2erlang(Array.get(obj, i), type.content[0]);
            }
            return new OtpErlangList(vv);
        } else if (type.kind == 't') {
            final OtpErlangObject[] vv = new OtpErlangObject[len];
            for (int i = 0; i < len; i++) {
                vv[i] = TypeConverter.java2erlang(Array.get(obj, i), type.content[i]);
            }
            return new OtpErlangTuple(vv);
        } else {
            TypeConverter.failConversion(obj, type);
        }
    }
    if (type.kind == 's' && obj != null) {
        return new OtpErlangString(obj.toString());
    }
    if (type.kind == 'b' && obj != null) {
        return new OtpErlangBinary(obj.toString().getBytes());
    }
    TypeConverter.failConversion(obj, type);
    return null;
}
Also used : OtpErlangChar(com.ericsson.otp.erlang.OtpErlangChar) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangMap(com.ericsson.otp.erlang.OtpErlangMap) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) OtpErlangBinary(com.ericsson.otp.erlang.OtpErlangBinary) OtpErlangPid(com.ericsson.otp.erlang.OtpErlangPid) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) Collection(java.util.Collection) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) OtpErlangRef(com.ericsson.otp.erlang.OtpErlangRef) Map(java.util.Map) OtpErlangMap(com.ericsson.otp.erlang.OtpErlangMap) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString)

Example 3 with OtpErlangPid

use of com.ericsson.otp.erlang.OtpErlangPid in project erlide_eclipse by erlang.

the class NewProcessEvent method execute.

@Override
public void execute(final ErlangDebugTarget debugTarget) {
    final OtpErlangTuple t = (OtpErlangTuple) cmds[1];
    final OtpErlangPid pid = (OtpErlangPid) t.elementAt(0);
    final ErlangProcess erlangProcess = debugTarget.getOrCreateErlangProcess(pid);
    final OtpErlangAtom statusA = (OtpErlangAtom) t.elementAt(2);
    final String status = statusA.atomValue();
    erlangProcess.setStatus(status);
    final OtpErlangTuple initialCall = (OtpErlangTuple) t.elementAt(1);
    erlangProcess.setInitialCall(new ErlangFunctionCall(initialCall));
    erlangProcess.fireCreationEvent();
}
Also used : OtpErlangPid(com.ericsson.otp.erlang.OtpErlangPid) ErlangFunctionCall(org.erlide.util.ErlangFunctionCall) ErlangProcess(org.erlide.backend.debug.model.ErlangProcess) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom)

Example 4 with OtpErlangPid

use of com.ericsson.otp.erlang.OtpErlangPid in project erlide_eclipse by erlang.

the class NewStatusEvent method execute.

@Override
public void execute(final ErlangDebugTarget debugTarget) {
    final OtpErlangPid pid = (OtpErlangPid) cmds[1];
    final ErlangProcess erlangProcess = debugTarget.getOrCreateErlangProcess(pid);
    final OtpErlangAtom sa = (OtpErlangAtom) cmds[2];
    final String status = sa.atomValue();
    if ("break".equals(status)) {
        handleBreakStatus(erlangProcess, status);
    } else if ("exit".equals(status)) {
        handleExitStatus(erlangProcess, status);
    } else if ("running".equals(status)) {
        handleRunningStatus(erlangProcess, status);
    } else if ("idle".equals(status)) {
        handleIdleStatus(erlangProcess, status);
    } else {
        erlangProcess.setStatus(status);
        erlangProcess.fireChangeEvent(DebugEvent.STATE | DebugEvent.CHANGE);
    }
}
Also used : OtpErlangPid(com.ericsson.otp.erlang.OtpErlangPid) ErlangProcess(org.erlide.backend.debug.model.ErlangProcess) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom)

Example 5 with OtpErlangPid

use of com.ericsson.otp.erlang.OtpErlangPid in project erlide_eclipse by erlang.

the class ErlideDebug method startDebug.

@SuppressWarnings("boxing")
public static OtpErlangPid startDebug(final IOtpRpc backend, final int debugFlags, OtpErlangPid parentPid) throws DebugException {
    OtpErlangObject res = null;
    try {
        res = backend.call(ErlideDebug.ERLIDE_DEBUG, "start_debug", "i", debugFlags);
    } catch (final RpcException e) {
        ErlLogger.warn(e);
    }
    if (res instanceof OtpErlangTuple) {
        final OtpErlangTuple t = (OtpErlangTuple) res;
        final OtpErlangObject o = t.elementAt(1);
        final IStatus s = new Status(IStatus.ERROR, BackendActivator.PLUGIN_ID, DebugException.REQUEST_FAILED, o.toString(), null);
        throw new DebugException(s);
    }
    final OtpErlangPid pid = (OtpErlangPid) res;
    // TODO bake in this in start_debug
    backend.send(pid, OtpErlang.mkTuple(ErlideDebug.PARENT_ATOM, parentPid));
    return pid;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IStatus(org.eclipse.core.runtime.IStatus) OtpErlangPid(com.ericsson.otp.erlang.OtpErlangPid) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) RpcException(org.erlide.runtime.rpc.RpcException) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) DebugException(org.eclipse.debug.core.DebugException)

Aggregations

OtpErlangPid (com.ericsson.otp.erlang.OtpErlangPid)15 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)10 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)8 OtpErlangAtom (com.ericsson.otp.erlang.OtpErlangAtom)4 RpcException (org.erlide.runtime.rpc.RpcException)4 OtpErlangList (com.ericsson.otp.erlang.OtpErlangList)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 ErlangProcess (org.erlide.backend.debug.model.ErlangProcess)2 OtpErlangBinary (com.ericsson.otp.erlang.OtpErlangBinary)1 OtpErlangChar (com.ericsson.otp.erlang.OtpErlangChar)1 OtpErlangDecodeException (com.ericsson.otp.erlang.OtpErlangDecodeException)1 OtpErlangLong (com.ericsson.otp.erlang.OtpErlangLong)1 OtpErlangMap (com.ericsson.otp.erlang.OtpErlangMap)1 OtpErlangRangeException (com.ericsson.otp.erlang.OtpErlangRangeException)1 OtpErlangRef (com.ericsson.otp.erlang.OtpErlangRef)1 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)1 IOException (java.io.IOException)1 Collection (java.util.Collection)1 Map (java.util.Map)1