ESBase join(Call eval, int length) throws Throwable { String separator = length == 0 ? "," : eval.getArg(0).toString(); ESObject array = eval.getArg(-1).toObject(); return join(array, separator); }
/** XXX: not right */ public ESBase toPrimitive(int hint) throws Throwable { Global resin = Global.getGlobalProto(); Call eval = resin.getCall(); eval.global = resin.getGlobal(); try { ESBase fun = hasProperty(hint == STRING ? TO_STRING : VALUE_OF); if (fun instanceof ESClosure || fun instanceof Native) { eval.stack[0] = this; eval.top = 1; ESBase value = fun.call(eval, 0); if (value instanceof ESBase && !(value instanceof ESObject)) return value; } fun = hasProperty(hint == STRING ? VALUE_OF : TO_STRING); if (fun instanceof ESClosure || fun instanceof Native) { eval.stack[0] = this; eval.top = 1; ESBase value = fun.call(eval, 0); if (value instanceof ESBase && !(value instanceof ESObject)) return value; } throw new ESException("cannot convert object to primitive type"); } finally { resin.freeCall(eval); } }
ESBase slice(Call eval, int length) throws Throwable { ESObject obj = eval.getArg(-1).toObject(); ESBase lenObj = obj.getProperty(LENGTH); int len = lenObj.toInt32(); ESArray array = Global.getGlobalProto().createArray(); if (len <= 0) return array; int start = 0; if (length > 0) start = eval.getArg(0).toInt32(); if (start < 0) start += len; if (start < 0) start = 0; if (start > len) return array; int end = len; if (length > 1) end = eval.getArg(1).toInt32(); if (end < 0) end += len; if (end < 0) return array; if (end > len) end = len; if (start >= end) return array; for (int i = 0; i < end - start; i++) { ESBase value = obj.hasProperty(start + i); if (value != null) array.setProperty(i, value); } array.setProperty(LENGTH, ESNumber.create(end - start)); return array; }
private int compare(ESBase cmp, ESBase a, ESBase b) throws Throwable { if (a == b) return 0; else if (a == esUndefined) return 1; else if (b == esUndefined) return -1; else if (a == esNull) return 1; else if (b == esNull) return -1; else if (cmp != null) { // Call eval = new Call(ESGlobal.getGlobalProto(), false); Global resin = Global.getGlobalProto(); Call eval = resin.getCall(); eval.stack[0] = esNull; eval.stack[1] = a; eval.stack[2] = b; eval.top = 1; int result = cmp.call(eval, 2).toInt32(); resin.freeCall(eval); return result; } else { String sa = a.toString(); String sb = b.toString(); return sa.compareTo(sb); } }
/** * Uploads the image to the server * * @param b * @param listener */ public void uploadImage(final Bitmap b, final OnResponseListener listener) { OkHttpClient httpClient = new OkHttpClient(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); // encode image as PNG, re-encoding as JPG may cause compression artefacts to be visible b.compress(Bitmap.CompressFormat.PNG, 0, bos); RequestBody requestBody = new MultipartBuilder() .type(MultipartBuilder.FORM) .addPart( // the filename parameter is needed to specify that this is indeed a file and not an // inline // attachment Headers.of( "Content-Disposition", "form-data; name=\"image\"; filename=\"image.png\""), RequestBody.create(MediaType.parse("image/png"), bos.toByteArray())) .build(); Request request = new Request.Builder().url(UPLOAD_ENDPOINT).post(requestBody).build(); Call call = httpClient.newCall(request); call.enqueue( new Callback() { @Override public void onFailure(Request request, IOException e) {} @Override public void onResponse(Response response) throws IOException { listener.onResponse(new ServerResponse(response.code(), response.body().string())); } }); }
ESBase unshift(Call eval, int length) throws Throwable { ESObject obj = eval.getArg(-1).toObject(); ESBase lenObj = obj.getProperty(LENGTH); int len = lenObj.toInt32(); if (len < 0) len = 0; if (length == 0) return ESNumber.create(0); for (int i = len - 1; i >= 0; i--) { ESBase value = obj.getProperty(i); if (value == null) obj.delete(ESString.create(length + i)); else obj.setProperty(length + i, value); } for (int i = 0; i < length; i++) { ESBase value = eval.getArg(i); if (value == null) obj.delete(ESString.create(i)); else obj.setProperty(i, value); } ESNumber numLen = ESNumber.create(len + length); obj.setProperty(LENGTH, numLen); return numLen; }
/** * Implements CallListener.incomingCallReceived. When a call is received creates a call panel and * adds it to the main tabbed pane and plays the ring phone sound to the user. */ public void incomingCallReceived(CallEvent event) { Call sourceCall = event.getSourceCall(); CallPanel callPanel = new CallPanel(this, sourceCall, GuiCallParticipantRecord.INCOMING_CALL); mainFrame.addCallPanel(callPanel); if (mainFrame.getState() == JFrame.ICONIFIED) mainFrame.setState(JFrame.NORMAL); if (!mainFrame.isVisible()) mainFrame.setVisible(true); mainFrame.toFront(); this.callButton.setEnabled(true); this.hangupButton.setEnabled(true); NotificationManager.fireNotification( NotificationManager.INCOMING_CALL, null, "Incoming call recived from: " + sourceCall.getCallParticipants().next()); activeCalls.put(sourceCall, callPanel); this.setCallPanelVisible(true); }
/*package*/ public ConnectionBase( Context context, String dialString, CallTracker ct, Call parent, CallDetails moCallDetails) { createWakeLock(context); acquireWakeLock(); owner = ct; h = new MyHandler(owner.getLooper()); this.dialString = dialString; if ((moCallDetails != null) && (moCallDetails.call_domain == CallDetails.RIL_CALL_DOMAIN_PS)) this.address = dialString; else this.address = PhoneNumberUtils.extractNetworkPortionAlt(dialString); this.postDialString = PhoneNumberUtils.extractPostDialPortion(dialString); index = -1; isIncoming = false; cnapName = null; createTime = System.currentTimeMillis(); callDetails = moCallDetails; if (parent != null) { this.parent = parent; // for the cdma three way call case, do not change parent state // pass remote caller id in cdma 3 way call only if (parent.state == Call.State.ACTIVE) { cnapNamePresentation = Connection.PRESENTATION_ALLOWED; numberPresentation = Connection.PRESENTATION_ALLOWED; parent.attachFake(this, Call.State.ACTIVE); } else { // MO call for Gsm & Cdma, set state to dialing parent.attachFake(this, Call.State.DIALING); } } }
private void eventRxMessageException( int callSeqId, String exceptionName, String exceptionDescription) { if (callSeqId == -1 && exceptionName.equals("Amos3.Session.Expired")) { // Disconnect disconnect(); // Reconnect connect(); // Reload buffer Iterator<Integer> itr = OutstandingCalls.keySet().iterator(); while (itr.hasNext()) { int callSeqIdInner = itr.next(); queueTx(callSeqIdInner, OutstandingCalls.get(callSeqIdInner).getTx()); } // Skip error process return; } Call call = OutstandingCalls.get(callSeqId); exception( exceptionName, exceptionDescription + " (callId: " + callSeqId + " methodName='" + call.getMethodName() + "')"); }
public SearchResult searchFor(String pattern, String threadName) { pattern = pattern.toLowerCase(Locale.US); Set<MethodInfo> methods = new HashSet<MethodInfo>(); Set<Call> calls = new HashSet<Call>(); Call topLevelCall = getThread(threadName).getTopLevelCall(); if (topLevelCall == null) { // no matches return new SearchResult(methods, calls); } // Find all methods matching given pattern called on given thread for (MethodInfo method : getMethods().values()) { String fullName = method.getFullName().toLowerCase(Locale.US); if (fullName.contains(pattern)) { // method name matches if (method.getInclusiveTime(threadName, ClockType.GLOBAL) > 0) { // method was called in this thread methods.add(method); } } } // Find all invocations of the matched methods Iterator<Call> iterator = topLevelCall.getCallHierarchyIterator(); while (iterator.hasNext()) { Call c = iterator.next(); MethodInfo method = getMethod(c.getMethodId()); if (methods.contains(method)) { calls.add(c); } } return new SearchResult(methods, calls); }
/** Handle a dial request */ public void handleDialRequest(String phoneNumber) { try { System.err.println( "Audio Static:" + PhoneManager.isUseStaticLocator() + " Using:" + PhoneManager.isUsingMediaLocator()); // cancel call request if no Media Locator if (PhoneManager.isUseStaticLocator() && PhoneManager.isUsingMediaLocator()) { return; } PhoneManager.setUsingMediaLocator(true); SessionDescription sdpData = mediaManager.generateSdpDescription(); Call call = sipManager.establishCall(phoneNumber, sdpData.toString()); if (call == null) return; call.setLocalSdpDescription(sdpData); call.addStateChangeListener(this); Interlocutor interlocutor = new Interlocutor(); interlocutor.setCall(call); guiManager.addInterlocutor(interlocutor); } catch (Exception e) { Log.error("handleDialRequest", e); } }
@Test public void testConvertsExpectationValueToActionReturnType() throws Exception { Call call = new Call(new StaticInvocation(calculator, Calculator.SUM)); call.addInput("2", "1"); call.expect("3"); call.execute(); assertTrue(call.wasRight()); }
/* Receive a response. * Because only one receiver, so no synchronization on in. */ protected void receiveResponse() { if (shouldCloseConnection.get()) { return; } touch(); try { // See HBaseServer.Call.setResponse for where we write out the response. // It writes the call.id (int), a flag byte, then optionally the length // of the response (int) followed by data. // Read the call id. int id = in.readInt(); if (LOG.isDebugEnabled()) LOG.debug(getName() + " got value #" + id); Call call = calls.get(id); // Read the flag byte byte flag = in.readByte(); boolean isError = ResponseFlag.isError(flag); if (ResponseFlag.isLength(flag)) { // Currently length if present is unused. in.readInt(); } int state = in.readInt(); // Read the state. Currently unused. if (isError) { if (call != null) { //noinspection ThrowableInstanceNeverThrown call.setException( new RemoteException(WritableUtils.readString(in), WritableUtils.readString(in))); } } else { Writable value = ReflectionUtils.newInstance(valueClass, conf); value.readFields(in); // read value // it's possible that this call may have been cleaned up due to a RPC // timeout, so check if it still exists before setting the value. if (call != null) { call.setValue(value); } } calls.remove(id); } catch (IOException e) { if (e instanceof SocketTimeoutException && remoteId.rpcTimeout > 0) { // Clean up open calls but don't treat this as a fatal condition, // since we expect certain responses to not make it by the specified // {@link ConnectionId#rpcTimeout}. closeException = e; } else { // Since the server did not respond within the default ping interval // time, treat this as a fatal condition and close this connection markClosed(e); } } finally { if (remoteId.rpcTimeout > 0) { cleanupCalls(remoteId.rpcTimeout); } } }
public void updateParent(Call oldParent, Call newParent) { if (newParent != oldParent) { if (oldParent != null) { oldParent.detach(this); } newParent.attachFake(this, Call.State.ACTIVE); parent = newParent; } }
public void dispatchCall(Call call) { Employee emp = getHandlerForCall(call); if (emp != null) { emp.pickCall(call); call.setHandler(emp); } else { call.reply("sorry!"); callQueues.get(call.getRank()).add(call); } }
@Test public void testAcceptsExceptionsAsValidExpectations() throws Exception { StaticInvocation divide = new StaticInvocation(calculator, Calculator.DIVIDE); Call call = new Call(divide); call.addInput("7", "0"); call.expect(ShouldBe.instanceOf(ArithmeticException.class)); call.execute(); assertTrue(call.wasRight()); }
@Test public void testReportsAFailureIfOuputIsUnexpected() throws Exception { Call call = new Call(new StaticInvocation(calculator, Calculator.ADD)); call.addInput("3"); call.expect(ShouldBe.equal(3)); call.will(Annotate.wrong(annotatable)).when(ResultIs.wrong()); call.execute(); verify(annotatable).annotate(any(WrongAnnotation.class)); }
@Test public void testReportsASuccessIfOuputMatchesExpectation() throws Exception { Call call = new Call(new StaticInvocation(calculator, Calculator.SUM)); call.addInput("5", "2"); call.expect(ShouldBe.equal(7)); call.will(Annotate.right(annotatable)).when(ResultIs.right()); call.execute(); verify(annotatable).annotate(any(RightAnnotation.class)); }
public void eventRxMessageSuccess(int callSeqId, JavaScriptObject reply) { // Fetch call Call call = OutstandingCalls.remove(new Integer(callSeqId)); // Publish queue length pushlishQueueLength(); // Callback done call.done(reply); }
public void fakeHoldBeforeDialIms() { if (parent != null) { parent.detach(this); } parent = owner.backgroundCallIms; parent.attachFake(this, Call.State.HOLDING); onStartedHolding(); }
private void doOperatorTask() throws ClassNotFoundException, IOException { BlockingTaskSummaryResponseHandler handler = new BlockingTaskSummaryResponseHandler(); client.getTasksAssignedAsPotentialOwner("operator", "en-UK", handler); List<TaskSummary> sums = handler.getResults(); assertNotNull(sums); assertEquals(1, sums.size()); BlockingTaskOperationResponseHandler startTaskOperationHandler = new BlockingTaskOperationResponseHandler(); client.start(sums.get(0).getId(), "operator", startTaskOperationHandler); BlockingGetTaskResponseHandler getTaskHandler = new BlockingGetTaskResponseHandler(); client.getTask(sums.get(0).getId(), getTaskHandler); Task operatorTask = getTaskHandler.getTask(); BlockingGetContentResponseHandler getContentHandler = new BlockingGetContentResponseHandler(); client.getContent(operatorTask.getTaskData().getDocumentContentId(), getContentHandler); Content content = getContentHandler.getContent(); assertNotNull(content); ByteArrayInputStream bais = new ByteArrayInputStream(content.getContent()); ObjectInputStream ois = new ObjectInputStream(bais); Map<String, Object> deserializedContent = (Map<String, Object>) ois.readObject(); Call restoredCall = (Call) deserializedContent.get("call"); persistenceService.storeCall(restoredCall); Emergency emergency = new Emergency(); emergency.setCall(restoredCall); emergency.setLocation(new Location(1, 2)); emergency.setType(Emergency.EmergencyType.HEART_ATTACK); emergency.setNroOfPeople(1); persistenceService.storeEmergency(emergency); trackingService.attachEmergency(restoredCall.getId(), emergency.getId()); Map<String, Object> info = new HashMap<String, Object>(); info.put("emergency", emergency); ContentData result = new ContentData(); result.setAccessType(AccessType.Inline); result.setType("java.util.Map"); ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(bos); out.writeObject(info); out.close(); result.setContent(bos.toByteArray()); BlockingTaskOperationResponseHandler completeTaskOperationHandler = new BlockingTaskOperationResponseHandler(); client.complete(sums.get(0).getId(), "operator", result, completeTaskOperationHandler); }
public Client(String dxservice, String username, String password) { try { call = (Call) service.createCall(); call.setTargetEndpointAddress(dxservice); call.setTimeout(callTimeout); call.setUseSOAPAction(true); call.setProperty(HTTPConstants.REQUEST_HEADERS, encodeAuth(username, password)); } catch (Exception e) { throw new RuntimeException(e); } }
/** {@inheritDoc} */ @Override public String toString() { if (context == null) return ""; StringBuilder builder = new StringBuilder(); for (Call call : context) { builder.append(call.toString()); builder.append(" "); } String tmp = builder.toString(); return tmp.trim(); }
/** * Fired when a call is received * * @param evt CallEvent */ public void callReceived(CallEvent evt) { try { Call call = evt.getSourceCall(); Interlocutor interlocutor = new Interlocutor(); interlocutor.setCall(call); guiManager.addInterlocutor(interlocutor); call.addStateChangeListener(this); // handleAnswerRequest(interlocutor); } catch (Exception e) { Log.error("callReceived", e); } }
private void relaunchedFromDialer(boolean showDialpad) { mShowDialpadRequested = showDialpad; mAnimateDialpadOnShow = true; if (mShowDialpadRequested) { // If there's only one line in use, AND it's on hold, then we're sure the user // wants to use the dialpad toward the exact line, so un-hold the holding line. final Call call = CallList.getInstance().getActiveOrBackgroundCall(); if (call != null && call.getState() == State.ONHOLD) { TelecomAdapter.getInstance().unholdCall(call.getId()); } } }
public boolean oldMatches(CallContext other) { if (context.size() != other.context.size()) return false; if (other.hcode == hcode) return true; for (int i = 0; i < context.size(); i++) { Call call1 = context.get(i); Call call2 = other.context.get(i); if (!call1.matches(call2)) { return false; } } return false; }
/** * 2 replied calls are equal, if there phone number is equal. * * @param o the call to compare with * @return true, if o is a {@link RepliedCall} and carries the same phone number as this; false, * else */ @Override public boolean equals(Object o) { Call that = null; // Workaround for ORMDroid's nested Object. if (this.getNumber() == null) return false; if (o instanceof RepliedCall) { that = (Call) o; return this.getNumber().equals(that.getNumber()); } return false; }
ESBase push(Call eval, int length) throws Throwable { ESObject obj = eval.getArg(-1).toObject(); ESBase lenObj = obj.getProperty(LENGTH); int len = lenObj.toInt32(); if (len < 0) len = 0; for (int i = 0; i < length; i++) obj.setProperty(len + i, eval.getArg(i)); ESNumber newLen = ESNumber.create(len + length); obj.setProperty(LENGTH, newLen); return newLen; }
ESBase splice(Call eval, int length) throws Throwable { if (length < 2) return esUndefined; ESObject obj = eval.getArg(-1).toObject(); int index = eval.getArg(0).toInt32(); int count = eval.getArg(1).toInt32(); boolean single = count == 1; ESBase lenObj = obj.getProperty(LENGTH); int len = lenObj.toInt32(); if (index < 0) index += len; if (index < 0) index = 0; if (count < 0) count = 0; if (index + count > len) count = len - index; ESBase value; if (count < 1) value = esUndefined; else { value = Global.getGlobalProto().createArray(); for (int i = 0; i < count; i++) value.setProperty(i, obj.getProperty(index + i)); } int delta = length - 2 - count; if (delta < 0) { for (int i = 0; i < len - count; i++) { ESBase temp = obj.getProperty(i + index + count); if (temp == null) obj.delete(ESString.create(i + index + count + delta)); else obj.setProperty(i + index + count + delta, temp); } } else if (delta > 0) { for (int i = len - count - 1; i >= 0; i--) { ESBase temp = obj.getProperty(i + index + count); if (temp == null) obj.delete(ESString.create(i + index + count + delta)); else obj.setProperty(i + index + count + delta, temp); } } for (int i = 0; i < length - 2; i++) obj.setProperty(i + index, eval.getArg(i + 2)); obj.setProperty(LENGTH, ESNumber.create(len - count + length - 2)); return value; }
public <R> R check(Call instance) { R r1 = null; R r2 = null; for (int i = 0; i < 50; i++) { r1 = (R) instance.method(map1); r2 = (R) instance.method(map2); if (r1 != null && r1.equals(r2)) return r1; if (i > 30) { try { Thread.sleep(i); } catch (InterruptedException e) { e.printStackTrace(); } } else Thread.yield(); } Assert.assertEquals(map1, map2); System.out.print(map1); System.out.print(map2); if (r1 != null) Assert.assertEquals(r1.toString(), r2.toString()); return (R) r1; }