processJsonRequest($paramJson); echo json_encode($result); class Server { public function processJsonRequest($stringParam) { $paramObj = json_decode($stringParam, true); return $this -> processRequest($paramObj, $silent); } public function processRequest($paramObj) { $type = $paramObj['request_type']; switch($type) { case 'add_numbers' : $response = $this -> addNumbers($paramObj); break; case 'get_route_length' : $response = $this -> getRouteLength($paramObj); break; case 'segment_route' : $response= $this->segmentRoute($paramObj); break; default : $response = array('server' => 'Unknown operation!'); break; } return $response; } public function addNumbers($paramObj) { $a=$paramObj["a"]; $b=$paramObj["b"]; return array('server' => ($a+$b)); } public function getRouteLength($paramObj) { $route=$paramObj["route"]; $handle = new RouteHandler(); $length=$handle->getRouteLength($route); return array('server' => $length); } public function segmentRoute($paramObj) { $route=$paramObj["route"]; $routeStr=""; // mopsi server uses reverse... for($i=count($route)-1;$i>=0;$i--){ $routeStr.=$route[$i]["lat"]." "; $routeStr.=$route[$i]["lng"]." "; $routeStr.=floor($route[$i]["time"]/1000)."\n"; } $dir="/home/tko/mopsi/routes/lamad_tmp/"; $file=$dir."route.txt"; $fw = @fopen($file, "w"); if ($fw) { fwrite($fw, $routeStr); } fclose($fw); $handle = new RouteHandler(); $result=$handle->segmentRouteRemotely($file,0); $resultArray=array(); if($result!=""){ $lines=explode("\n", $result); $path=array(); for($i=1;$i1){ $point=array(); $point["lat"]=(float)($comp[0]); $point["lng"]=(float)($comp[1]); $point["time"]=$comp[2]; array_push($path,$point); } } } // format result here return array('server' => $resultArray); } } ?>