One police officer has been shot and killed and another two wounded after a gunman opened fire before being killed himself.