Asterisk Parallel Calling Find Answered Number - parallel-processing

I am trying asterisk parallel calling by doing.
same => n,dial(DAHDI/g0/09*********&DAHDI/g0/09*********,20,mM(ANSWERED))
But the problem is that how can know which number picks the call because the call is forwarding to macro and ${EXTEN}, ${CDR(dst)} variables dint gave me the desired result.
So how to get answered person's number in parallel calling?

You can check dstchannel cdr variable.
Also very likly you have other variables, for example CHANNEL set to channel called, you can see all by do DumpChan call in y our macro,it will show you all variables.
As other option you can do calling via Local channel(via dialplan), in which you run ANSWERED macro.

Related

Bash: No return value when calling a function

I'm new to stackoverflow and bash scripting, so go easy on me! I've been struggling with a bash script I've been writing: when I try to call a function 'main' from my script like so:
variable=$("main -t $path/$i")
I get the error "main -t ./folder: No such file or directory"; any ideas?
Thanks in advance!
EDIT: Thanks Jkbkot, I'm now calling it like this:
variable=$(main -t "$path/$i")
The original error is sorted but something is still up: 'variable' seemingly isn't being assigned the value echoed in the function, though calling the function manually prints the correct value. Why might this happen?
EDIT: It seems I'm calling and echoing correctly, but when calling 'main' it seems to behave differently when called recursively to the initial call. For example it runs fine up to:
variable=$(main -t "$path/$i") #A line within 'main'
Then begins again, as expected, but this time it stops as soon as it comes across a 'break', apparently breaking out of the entire function call rather that just the 'case' it's currently in. Is there some quirk to 'break' in bash that I'm unaware of?
NOTE: Unfortunately, the script is an assignment from my university, and many of its students and teachers use this website, so publicly posting my solution would likely have negative consequences.
You have to call it without the quotes:
variable=$(main -t $path/$i)
and as #janos says, you might need the quotes around the variables in case they might contain spaces, etc.:
variable=$(main -t "$path/$i")

Mathematica - can I define a block of code using a single variable?

It has been a while since I've used Mathematica, and I looked all throughout the help menu. I think one problem I'm having is that I do not know what exactly to look up. I have a block of code, with things like appending lists and doing basic math, that I want to define as a single variable.
My goal is to loop through a sequence and when needed I wanted to call a block of code that I will be using several times throughout the loop. I am guessing I should just put it all in a loop anyway, but I would like to be able to define it all as one function.
It seems like this should be an easy and straightforward procedure. Am I missing something simple?
This is the basic format for a function definition in Mathematica.
myFunc[par1_,par2_]:=Module[{localVar1,localVar2},
statement1; statement2; returnStatement ]
Your question is not entirely clear, but I interpret that you want something like this:
facRand[] :=
({b, x} = Last#FactorInteger[RandomInteger[1*^12]]; Print[b])
Now every time facRand[] is called a new random integer is factored, global variables b and x are assigned, and the value of b is printed. This could also be done with Function:
Clear[facRand]
facRand =
({b, x} = Last#FactorInteger[RandomInteger[1*^12]]; Print[b]) &
This is also called with facRand[]. This form is standard, and allows addressing or passing the symbol facRand without triggering evaluation.

Setting a watch point in GDB

I am operating a huge code base and want to monitor a value of a particular variable (which is buried deep down inside one of the files)especially when it gets set to zero.
1) Variable does not belong to global scope .Is there a better option than to first set breakpoint into the function where it is defined and then set the watch point?
2) After trying the option in 1 I see that watch point gets deleted after a while saying its out of frame which used this .This way it adds to the tediousness of the procedure since I have to add it again and again?Any workarounds?
3) Is there a way to check ie watch if a particular variable is equal to 0( or any specific constant)?
want to monitor a value of a particular variable
Often this is not the best approach, especially in large codebases.
What you really likely want to do is understand the invariants, and assert that they are true on entry and exit to various parts of the code.
1) Variable does not belong to global scope .Is there a better option than to first set breakpoint into the function where it is defined and then set the watch point?
No. For automatic (stack) variables you have to be in the scope where the variable is "active".
What you can do is set a breakpoint on some line, and attach commands to that breakpoint that will set the watchpoint automatically, e.g.
(gdb) break foo.c:123
(gdb) commands 1
silent
watch some_local
continue
end
3) Is there a way to check ie watch if a particular variable is equal to 0
You can't do that with a watchpoint, but you can with a conditional breakpoint:
(gdb) break foo.c:234 if some_local == 0
I will assume that you are using Linux. You can try this:
The first step is to make the variable static, like:
static int myVar;
Then, after compiling your code using -ggdb, you must discover the address of the variable inside your binary, like so (I have used a real case as example):
readelf -s pdv | grep tmp | c++filt
In my situation, the output is:
47: 081c1474 4 OBJECT LOCAL DEFAULT 25 startProc(int)::tmp
The address in this case is 081c1474. Now you can set a watch point inside GDB:
watch *0x081c1474
Mind the "*0x" before the correct address.
I know this question is old, but I hope it helps anyway.

How to stop prolog goal executing more than once?

I have a fact and a goal like below:
disconnected.
join :- disconnected, time(T), send(T).
Once this goal executes it should make disconnected false and thus not execute again. I am new to Prolog so I am a bit stuck. I am sure it's something really simple but can't figure it out at the moment. Any ideas?
You might use assert or retract to change the known facts. Or you might use global variables. I am not sure how standard that is.
The easiest would be to declare your join with two parameters: input parameter that signifies the current state, and an output parameter signifying the new state.

Correct use of findall/3, especially the first template argument

i know there is a build-in function findall/3 in prolog,
and im trying to find the total numbers of hours(Thrs) and store them in a list, then sum the list up. but it doesnt work for me. here is my code:
totalLecHrs(LN,THrs) :-
lecturer(LN,LId),
findall(Thrs, lectureSegmentHrs(CC,LId,B,E,THrs),L),
sumList(L,Thrs).
could you tell me what's wrong with it? thanks a lot.
You need to use a "dummy" variable for Hours in the findall/3 subgoal. What you wrote uses THrs both as the return value for sumList/2 and as the variable to be listed in L by findall/3. Use X as the first argument of findall and in the corresponding subgoal lectureSegmentHrs/5 as the last argument.
It looks like the problem is that you're using the same variable (Thrs) twice for different things. However it's hard to tell as you've also used different capitalisation in different places. Change the findall line so that the initial variable has the same capitalisation in the lectureSegmentHrs call. Then use a different variable completely to get the final output value (ie the one that appears in sumList and in the return slot of the entire predicate).
You need to use a different variable because Prolog does not support variable reassignment. In a logical language, the notion of reassigning a variable is inherently impossible. Something like the following may seem sensible...
...
X = 10,
X = 11,
...
But you have to remember that , in Prolog is the conjunction operator. You're effectively telling Prolog to find a solution to your problem where X is both 10 and 11 at the same time. So it's obviously going to tell you that that can't be done.
Instead you have to just make up new variable names as you go along. Sometimes this does get a bit annoying but it's just goes with the territory of a logical languages.

Resources